• Advertisement
Sign in to follow this  

glReadPixels problem

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use glReadPixels to read the depth of the pixel at a particular window coordinate, The problem that winZ is always 1.0 I'm calling the following code after rendering my scene. Any common errors anyone can think of? glGetError() returns GL_NO_ERROR int winX = 400; // just for example int winY = 300; // just for example GLfloat winZ; glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); winY = viewport[3] - winY; glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);

Share this post


Link to post
Share on other sites
Advertisement
Make sure
- you have a RC attached to a HDC (on Windows)
- you do some rendering before the query
- you have your zBuffer enabled
- you don't perform a SwapBuffers before the query
(or you have PFD_SWAP_COPY set)
- your viewport is at least 400x300 in size

Share this post


Link to post
Share on other sites
Okay... It's not returning 1.0 but more like 0.98...

However, this is as small as it gets. Should it not be returning a number closer to 0 for the closer the pixels are to the camera? (if that makes sense?)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement