- function Selection : integer;
- var
- SelectBuffer : array[0..256] of GLUInt;
- Viewport : array[0..3] of Integer;
- Hits,i : Integer;
- HitZValue : GLUInt;
- Hit : GLUInt;
- begin
- glGetIntegerv(GL_VIEWPORT, @viewport);
- glSelectBuffer(256, @SelectBuffer);
- glRenderMode(GL_SELECT);
- glInitNames;
- glPushName(0);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix;
- glLoadIdentity;
- gluPickMatrix(xs, viewport[3]-ys, 1.0, 1.0, @viewport);
- gluPerspective(45.0, form1.ClientWidth/form1.ClientHeight, 1, 100);
- render;
- glMatrixMode(GL_PROJECTION);
- glPopMatrix;
- Hits := glRenderMode(GL_RENDER);
- Hit := High(GLUInt);
- HitZValue := High(GLUInt);
- 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;