Sign in to follow this  
Scarfy

glReadPixels problem

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this