Why is the z value read from glReadPixels always 1.0?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is the z value read from glReadPixels always 1.0?

Irene Tang
Hi, I want to transform screen coordinates to word coordinates?
I used gl2.glReadPixels(e.x, viewportMatrix[3] - e.y, 1, 1, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, FloatBuffer.wrap(winZ)) to get depth value of (x,y) in screen coordinates. But no matter how to change (x,y), the value of winZ is always 1.0. How can i get the actual depth value?
Reply | Threaded
Open this post in threaded view
|

Re: Why is the z value read from glReadPixels always 1.0?

elect
Have you bound the fbo before? How is the depth attached texture/renderBuffer?
Reply | Threaded
Open this post in threaded view
|

Re: Why is the z value read from glReadPixels always 1.0?

Irene Tang
I don't understand what you said. I think the reason might be that nothing ever rendered in the clicking point, so the z-depth would be the default 1.0.
Reply | Threaded
Open this post in threaded view
|

Re: Why is the z value read from glReadPixels always 1.0?

elect
Irene Tang wrote
I think the reason might be that nothing ever rendered in the clicking point, so the z-depth would be the default 1.0.
Well, then yes, it is like this. What you read is the default clear value for the depth buffer