- function TRenderer.GetSelectBufferHit : Integer;
- var
- SelectBuffer : array[0..512] of TGLUInt;
- Viewport : TVec4i;
- Hits,i : Integer;
- HitZValue : TGLUInt;
- Hit : TGLUInt;
- begin
- glGetIntegerv(GL_VIEWPORT, @viewport);
- glSelectBuffer(512, @SelectBuffer);
- glRenderMode(GL_SELECT);
- glInitNames;
- glPushName(0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- gluPickMatrix(MousePos.x, viewport[3]-MousePos.y, 1.0, 1.0, Viewport);
- gluPerspective(45.0, Form1.ClientWidth/Form1.ClientHeight, 0.1, 2048);
- Render;
- Hits := glRenderMode(GL_RENDER);
- 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;
- Result := Hit;
- end;