Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
share|improve this question

4 Answers 4

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

share|improve this answer
    
I have Ati on laptop :/ Thx :/ I will check this –  openglNewbie Nov 7 '10 at 20:29
    
So what can I use ? Test collision mouse-ray with triangles from meshes ? –  openglNewbie Nov 7 '10 at 20:35
    
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. –  r2d2rigo Nov 7 '10 at 23:19

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

share|improve this answer

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.

share|improve this answer

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().

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.