function TForm1.GetSelectBufferHit : Integer;
var
SelectBuffer : array[0..512] of TGLUInt;
Viewport : TVector4i;
Hits,i : Integer;
HitZValue : TGLUInt;
Hit : TGLUInt;
begin
ActivateRenderingContext(FDC, FRC);
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);
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;
Result := Hit;
end;
|