3
\$\begingroup\$

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);
\$\endgroup\$
3
\$\begingroup\$

Do you have an ATI card? I think they deprecated some portions of OpenGL (picking included) a long time ago.

\$\endgroup\$
  • \$\begingroup\$ I have Ati on laptop :/ Thx :/ I will check this \$\endgroup\$ – openglNewbie Nov 7 '10 at 20:29
  • \$\begingroup\$ So what can I use ? Test collision mouse-ray with triangles from meshes ? \$\endgroup\$ – openglNewbie Nov 7 '10 at 20:35
  • \$\begingroup\$ Yeah, you'll have to do you own picking. If you want tight results use triangle picking, or you can test against bounding boxes/spheres if you don't need that much precision. \$\endgroup\$ – r2d2rigo Nov 7 '10 at 23:19
3
\$\begingroup\$

OpenGL picking using the selection buffer is deprecated. If your scene is small enough, you should use colour-based picking; otherwise, you can use gluUnProject to obtain a world coordinate from a mouse coordinate and a depth read from the depth buffer using glReadPixels().

\$\endgroup\$
0
\$\begingroup\$

No one use OpenGL picking this days, you have to implement it yourself. Transforming from camera to worlds space is a bit tricky, here is a good article http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/MousePicking

\$\endgroup\$
0
\$\begingroup\$

Ok, but for 3d viewer application opengl isn't better ? My doesn't work, beacouse I have two mistakes: 1.

gluPerspective(45,(float)view[2]/(float)view[3],1.0,1500.0);

2.

gluPickMatrix(x,view[3]-y,1.0,1.0,view);

So it is looking that picking still works on ati, my friend said my that picking can be making by software implementation of opengl.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy