glReadPixels problem

Started by
3 comments, last by Scarfy 18 years, 1 month ago
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);
Parallel RealitiesProject: Starfighter
Advertisement
Do you even have a depth buffer? If you do, is depth testing enabled?
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
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?)
Parallel RealitiesProject: Starfighter
Ahh... it's okay. I've got it. Cheers.
Parallel RealitiesProject: Starfighter

This topic is closed to new replies.

Advertisement