picking doesnt work

heres my code:

GLint viewport[4];

glSelectBuffer(512,selectBuf);
glGetIntegerv(GL_VIEWPORT,viewport);
glRenderMode(GL_SELECT);
glInitNames();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

gluPickMatrix(mc_x, mc_y , 5, 5,viewport); //main characters x/y coordinates

glOrtho(0,640,0,480,-1,1); //for 2d drawing
glPushName(0);
glLoadName(0);
drawbackground();
glLoadName(1);
drawmaincharacter();
glLoadName(2);
drawmouse();
glPopName();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
hits = glRenderMode(GL_RENDER);
if (hits != 0)
{
processhits(hits);
}

but it always shows me 3 hits, everything is hit :frowning:

why doesnt it work

glRenderMode returns the number of hits when GL_SELECT is the flag used. You have to pick which one is in front using the information in the buffer…

look here

if you look at the proces****s function there, you can see that it looks through all the hit records and shows that you can get the z order information. You can use this to determine which one is closer to the camera.

Hope that helps

i dont have a z value
it just displays everything as a hit also if theres nothing hit