I have the following code:
void doSelect(int x, int y)
{
GLuint buff[64] = {0};
GLint hits, view[4];
int id;
int i;
GLuint *names = buff;
//set buffer
glSelectBuffer(64, buff);
glGetIntegerv(GL_VIEWPORT,
view);
//enter select mode
glRenderMode(GL_SELECT);
glPushName(0);
glMatrixMode(GL_PROJECTION
);
glPushMatrix();
glLoadIdentity();
//Restrict area to around mouse
gluPickMatrix(x-iw/2, y+ih/2, 5, 5, view);
glOrtho(-iw/2, iw/2, -ih/2, ih/2, -1, 1);
//DEBUG:
fprintf(stdout, "Picking: Mouse at %d, %d +++ Picking Coords: %d, %d\n", x, y, x, view[3]-y);
glMatrixMode(GL_MODELVIEW)
;
glInitNames();
doRender();
//restore normal views
glMatrixMode(GL_PROJECTION
);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
printf("%d hits:\n", hits);
for (i = 0; i < hits; i++)
fprintf(stdout, "Number: %d\n"
"Min Z: %d\n"
"Max Z: %d\n"
"Name on stack: %d\n",
(GLubyte)names[i * 4],
(GLubyte)names[i * 4 + 1],
(GLubyte)names[i * 4 + 2],
(GLubyte)names[i * 4 + 3]
);
fprintf(stdout, "\n");
//restore to model view to render to screen
glMatrixMode(GL_MODELVIEW)
;
}
Notice how the OpenGL coordnites is set to -Width/2 to Width/2 and -Height/2 to height/2, the mouse x,y are translated correctly, but somehow I am not registering any hits?
Am I doing something wrong?
Thanks in advanced
Start Free Trial