Sign in to follow this  

Reading the depth buffer with glReadPixels()

This topic is 3935 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

Hi there, I've got a wierd problem with glReadPixels: I'm using glReadPixels( x, y, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, buffer ); but the values in buffer are all in the range 0.99-1.0 . If I zoom in really really close to the scene, I start to see variation in these values towards a reasonable 0-1 range. It's as if glReadPixels() is assuming some tiny range for my depth values. The depth range is 0-1 (as in glDepthRange()), the pixel transfer depth bias and scale are 0 and 1 respectively. Perspective projection matrix is set up with znear of 1 and zfar of 1000. Reading the colour buffer produces correct results, and I know that the depth buffer itself is alright, because I'm getting perfectly fine depth testing. Hardware-wise, I've got an NVidia Quadro FX 3400 with the latest drivers. Does anybody have any ideas? Many thanks in advance...

Share this post


Link to post
Share on other sites
Not far - if I render a model at the origin, with the camera 100 units away, then I get the aforementioned 0.99-1.0 depth. If I zoom the camera to with, say, 1 unit of the model, I start seeing a wider range.

Share this post


Link to post
Share on other sites
Since the depth buffer has exponential precision I'd say it's reasonable to get that range at a distance of 100. Try reducing your far clip plane to let's say 200 and check your values then.

Share this post


Link to post
Share on other sites
Heya Lord Evil, thanks for your prompt replies! I did have some joy with changing the z planes - near Z having a far better effect on visible depth range than far (also with the added benefit of increasing z buffer precision). I've pushed it out pretty far (to 5 units), and it's still producing irritatingly washed out near white images, but I guess it'll have to do. It's a shame there isn't a non-linear scale that can be applied to pixel transfers.

Share this post


Link to post
Share on other sites

This topic is 3935 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.

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