JTW
12-12-2003, 07:45 AM
hi everyone;
for the most part, my picking code works fine. but what i can't figure out is that in addition to the object i click on, i always get an extra hit. for instance, even with only one object on the name stack, i get 2 hits returned if i click on the object, and 1 hit if i don't click on the object. except for the dummy pushname(0), i only push one name on the stack. any ideas?
in the DrawGLScene() function i have:
glLoadName(10);
object.render();
and the picking code is:
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x,768-y, 10.0f, 10.0f, viewport);
gluPerspective(45.0f,double(1024)/double(768),0.1f,100000.0f); // same as in projection mode
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
DrawGLScene();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
GLint hits;
// returning to normal rendering mode
hits = glRenderMode(GL_RENDER);
for the most part, my picking code works fine. but what i can't figure out is that in addition to the object i click on, i always get an extra hit. for instance, even with only one object on the name stack, i get 2 hits returned if i click on the object, and 1 hit if i don't click on the object. except for the dummy pushname(0), i only push one name on the stack. any ideas?
in the DrawGLScene() function i have:
glLoadName(10);
object.render();
and the picking code is:
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x,768-y, 10.0f, 10.0f, viewport);
gluPerspective(45.0f,double(1024)/double(768),0.1f,100000.0f); // same as in projection mode
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
DrawGLScene();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
GLint hits;
// returning to normal rendering mode
hits = glRenderMode(GL_RENDER);