What's wrong with this OpenGL model picking code?
Posted
by
openglNewbie
on Game Development
See other posts from Game Development
or by openglNewbie
Published on 2010-11-07T18:48:39Z
Indexed on
2011/01/12
17:58 UTC
Read the original article
Hit count: 212
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);
© Game Development or respective owner