// On a mouse click...
glSelectBuffer(...);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity();
gluPickMatrix(...);
gluPerspective(...);
glInitNames();
glPushName(0);
// This part is taking a long time...
RenderPickingScene(...);
// determine what was clicked on
hits = glRenderMode(GL_RENDER);
ProcessesPickingHits(hits);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
void RenderPickingScene(...)
{
glPushMatrix();
glRotatef(ViewpointRotationX, -1.0f, 0.0f, 0.0f);
glRotatef(ViewpointRotationY, 0.0f, -1.0f, 0.0f);
glRotatef(ViewpointRotationZ, 0.0f, 0.0f, -1.0f);
glTranslatef(-ViewpointPositionX, -ViewpointPositionY, -ViewpointPositionZ);
glLoadName(...);
// Draw the object(s)
glPushMatrix();
glTranslatef(ObjectPositionX, ObjectPositionY, ObjectPositionZ);
glRotatef(ObjectRotationZ, 0.0f, 0.0f, 1.0f);
glRotatef(ObjectRotationY, 0.0f, 1.0f, 0.0f);
glRotatef(ObjectRotationX, 1.0f, 0.0f, 0.0f);
glBindBufferARB(GL_ARRAY_BUFFER, VertexName);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, ColorName);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, NormalName);
glNormalPointer(GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, TexCoordName);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
// The object is just made up of quads
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, VBOName);
glDrawRangeElements(GL_QUADS, 0, IndexCurrentSize, IndexCurrentSize, GL_UNSIGNED_INT, NULL);
^--- THIS FUNCTION TAKES NEARLY 1 SECOND
glPopMatrix();
glPopMatrix();
}