PDA

View Full Version : picking problem (min max Z-buffer always zero)



desklamp
02-10-2009, 08:59 AM
I've drawn a simple cube and have implemented the ability to drag the cube. The problem is that the selection code always returns minZ and maxZ as zero.

This records the hits OK its just the Z-order that is always zero. The only other things I can think of that effect depth are:

in main()
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPT H);

at the start of draw()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

and in the init function:
glClearDepth(1.0);
glViewport(0, 0, w, h);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

The selection code is the standard stuff:


void gl_select(int x, int y)
{
GLuint buff[64] = {0};
GLint hits, view[4];
int id;

glSelectBuffer(64, buff);
glGetIntegerv(GL_VIEWPORT, view);
glRenderMode(GL_SELECT);

glInitNames();

glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix(x, y, 1.0, 1.0, view);
gluPerspective(120, 1.0, 0.0001, 1000.0);
glMatrixMode(GL_MODELVIEW);


glutSwapBuffers();
gl_draw();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
hits = glRenderMode(GL_RENDER);
list_hits(hits,buff);
}