Advertisement Jump to content
Sign in to follow this  
hazari

Problem with reading depth buffer

This topic is 3651 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 am trying to use glReadPixels to read pixel depth from depth buffer: GLfloat *pointDepth = new GLfloat; ... glReadPixels(x,y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, pointDepth); ... but almost in all points read the same depth 0.50000006. I am using a Dell laptop with NVIDIA GeForce 8400M GS display adapter. I do appreciate if somebody can help on this. I have spent almost all the day to fix this but I could not. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well for 1, what is your scene.

2.) Why dont you actually read the whole scene;

GLfloat *pointDepth = new GLfloat[width*height];

Then copy all of them.

Share this post


Link to post
Share on other sites
Quote:
Original post by hazari
GLfloat *pointDepth = new GLfloat;
glReadPixels(x,y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, pointDepth);
I would avoid the allocation, and just pass the address of a float variable on the stack. As to your problem, make sure that your context owns the pixel you are trying to read back (pixel ownership is not entirely straightforward), and also remember that the OpenGL coordinate system is upside down, so you may need to flip your y coordinate.

Share this post


Link to post
Share on other sites
Thanks for your comments. But I think I found the reason for problem. I use glDrawPixels function before glReadPixles. That is why I have same point depth in almost all pixels.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!