PDA

View Full Version : picking



desklamp
02-12-2009, 02:36 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);
}

Brolingstanz
02-15-2009, 06:01 PM
fyi, selection is deprecated and runs in software on consumer hw besides, afaik. Render to an object id buffer of some kind or just cast rays (preferably with some sort of spatial hierarchy optimization, e.g. kd-tree, octree, etc, etc, etc).