LibGDX How do I get the pixel Z coordinate from a FrameBuffer? (without shaders)

Hello guys!

I have a scene rendered into a FrameBuffer (for post processing) and a PerspectiveCamera.

What is the easiest way to get the depth value of the pixel from the middle of the FrameBuffer?
This did not work:

camera.unproject(Vector3 coords)

I need a function like that:

public float getZ(int pixelX,int pixelY,FrameBuffer frameBuffer)

Is it possible? If yes, how can I do that?
That’d be great if you include any code :smiley:

I never used LibGDX, but it seems to be using an OpenGL Framebuffer Object (FBO) with a renderbuffer attachment to hold the depth buffer. So you can use the following OpenGL function, after you’ve “bound” the FBO somehow, to retrieve the depth at a certain pixel:


glReadPixels(width/2, height/2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, pixels);

At least in a basic OpenGL application (with LWJGL) this returns proper depth values in the pixels ByteBuffer.