function TGLForm.GetSelectBufferHit : Integer;
var
SelectBuffer : array[0..512] of TGLUInt;
Viewport : TGLArrayi4;
Hits,i : Integer;
HitZValue : TGLUInt;
Hit : TGLUInt;
begin
glGetIntegerv(GL_VIEWPORT, @viewport);
glSelectBuffer(512, @SelectBuffer);
glRenderMode(GL_SELECT);
glInitNames;
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix;
glLoadIdentity;
gluPickMatrix(mx, viewport[3]-my, 1.0, 1.0, viewport);
gluPerspective(45.0, ClientWidth/ClientHeight, 0.1, 1000);
DrawScene;
glMatrixMode(GL_PROJECTION);
glPopMatrix;
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;
|