- procedure TForm1.OGLMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- var
- SelectBuffer : array[0..512] of TGLUInt;
- Viewport : TVector4i;
- Hits,i : Integer;
- HitZValue : TGLUInt;
- Hit : TGLUInt;
- begin
- if (x <> OldMousePos.x) or (y <> OldMousePos.y) then
- begin
- OldMousePos := Point(x,y);
- end
- else exit;
- ActivateRenderingContext(OGL.FDeviceContext,OGL.RenderingContext);
- glGetIntegerv(GL_VIEWPORT, @viewport);
- glSelectBuffer(512, @SelectBuffer);
- glRenderMode(GL_SELECT);
- glInitNames;
- glPushName(0);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- gluPickMatrix(x, viewport[3]-y, 1.0, 1.0, viewport);
- gluPerspective(45.0, OGL.Width/OGL.Height, 0.1, 1000);
- DrawScene;
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- Hits := glRenderMode(GL_RENDER);
- DeactivateRenderingContext;
- Hit := High(TGLUInt);
- HitZValue := High(TGLUInt);
- for i := 0 to Hits-1 do
- if SelectBuffer[(i*4)+1] < HitZValue then
- begin
- Hit := SelectBuffer[(i*4)+3];
- HitZValue := SelectBuffer[(i*4)+1];
- end;
- BHit := Hit;
- end;