OpenGL es 2.0 Read depth buffer
- by Brian
Hi!
As far as i know, we can't read the Z(depth) value in OpenGL ES 2.0.
So I am wondering how we can get the 3D world coordinates from a point on the 2D screen?
Actually I have some random thoughts might work. Since we can read the RGBA value by using glReadPixels, how about we duplicate the depth buffer and store it in a color buffer(say ColorforDepth). Of course there need to be some nice convention so that we don't lose any information of the depth buffer. And then when we need a point's world coordinates , we attach this ColorforDepth color buffer to the framebuffer and then render it. So when we use glReadPixels to read the depth information at this frame.
However, this will lead to 1 frame flash since the colorbuffer is a weird buffer translated from the depth buffer. I am still wondering if there is some standard way to get the depth in OpenGL es 2.0?
Thx in advance!:)