Hi,
I’m using the code below to pick the object under a mouse click. If I use the same gluPerspective parameters that I set during initialization, I get no hits. If I vary them, I get some hits, but the min Z, max Z values for the buffer entries are 0 (or close to 0). On top of that, I’ve tried with a very simple case, displaying a cube, and clicking on the front face, so that I should get two hits (another one for the back face), and glRenderMode only returns a hit.
void selection(int x, int y)
{
GLuint buffer[512] = {0};
GLint numberOfHits;
GLint viewport[4];
// Use buffer for selection
glSelectBuffer(512, buffer);
// Get viewport info
glGetIntegerv(GL_VIEWPORT, viewport);
// Switch to selection mode
glRenderMode(GL_SELECT);
// Clear the name's stack
glInitNames();
// Push one element onto the stack
glPushName(NULL);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// Restrict the drawing to an area around the cursor
gluPickMatrix(x, y, 1.0, 1.0, viewport);
// zNear=1000, zFar=10000 during initialization
//gluPerspective(fovy, ((GLdouble) windowWidth) / windowHeight, zNear, zFar);
gluPerspective(fovy, ((GLdouble) windowWidth) / windowHeight, 0.001, 1000);
// Draw the objects onto the screen
glMatrixMode(GL_MODELVIEW);
// Draw only the names in the stack, and fill the array
glutSwapBuffers();
display();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
// Get the number of objects drawn in that area
// Return to render mode
numberOfHits = glRenderMode(GL_RENDER);
list_hits(numberOfHits, buffer);
if (numberOfHits > 0)
{
int objectMinZ = buffer[1];
int objectName = buffer[3];
for (unsigned int i = 1; i < numberOfHits; i++)
{
if (buffer[i*4+1] < GLuint(objectMinZ))
{
objectMinZ = buffer[i*4+1];
objectName = buffer[i*4+3];
}
}
Side::selectSide(objectName);
}
}
Cheers,