What's wrong with this OpenGL model picking code?
- by openglNewbie
I am making simple model viewer using OpenGL. When I want to pick an object OpenGL returns nothing or an object that is in another place.
This is my code:
GLuint buff[1024] = {0};
GLint hits,view[4];
glSelectBuffer(1024,buff);
glGetIntegerv(GL_VIEWPORT, view);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x,y,1.0,1.0,view);
gluPerspective(45,(float)view[2]/(float)view[4],1.0,1500.0);
glMatrixMode(GL_MODELVIEW);
glRenderMode(GL_SELECT);
glLoadIdentity();
//I make the same transformations for normal render
glTranslatef(0, 0, -zoom);
glMultMatrixf(transform.M);
glInitNames();
glPushName(-1);
for(int j=0;j<allNodes.size();j++)
{
glLoadName(allNodes.at(j)->id);
allNodes.at(j)->Draw(textures);
}
glPopName();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);