PDA

View Full Version : trouble reading depth value at a single pixel



madmanchan
08-07-2003, 01:52 PM
Hi,

I'm trying to read the depth value at a single pixel location in the framebuffer, in a simple GLUT application.

When the user clicks the mouse at pixel location (x, y), my program execs the following code:

float depth;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

For some reason, the contents of depth is always equal to 1.0, even if I click on objects that clearly have depth <1.0. Anybody know why this would be?

Thanks,
Eric

Relic
08-08-2003, 02:34 AM
Mouse coordinates have top-left orign coordinates, OpenGL uses bottom-left.
Invert the y coordinate:
glReadPixels(x, windowClientHeight - 1 - y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
And if it's not that, have you enabled depth testing and the depth mask when drawing?

[This message has been edited by Relic (edited 08-08-2003).]

madmanchan
08-08-2003, 05:01 AM
Good call. I didn't have the depth test enabled when drawing. Thanks!

Eric