0

I use the following code to retrieve the depth buffer:

FloatBuffer pixels = ByteBuffer
    .allocateDirect(4).order(ByteOrder.nativeOrder()).asFloatBuffer();

GLES20.glReadPixels(pointx, pointy, 1, 1, 
    GLES20.GL_DEPTH_COMPONENT16, GLES20.GL_FLOAT, pixels);

Problem is, whichever point I am requesting, the pixels is giving me 0.0;

I have enabled the following in onSurfaceCreated:

GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
GLES20.glDepthFunc(GLES20.GL_LEQUAL);
GLES20.glDepthMask(true);
GLES20.glClearColor(1, 1, 1, 1);

I've been struggling with this issue for days! Please help.

xandy
  • 27,357
  • 8
  • 59
  • 64

1 Answers1

4

According to the OpenGL ES 2.0 docs, glReadPixels() doesn't support reading the depth buffer. What does glGetError() return?

Martin Stone
  • 12,682
  • 2
  • 39
  • 53
  • Thanks @Martin. I never noticed about this change. Well, no, geterror return 0; BTW, so how can I read the depth buffer from gles2? – xandy Jun 10 '11 at 09:01
  • One solution is to do a separate render pass, where you use a shader that fills the color buffer with depth values. This is what I've had to do in the past on DirectX 9. – Martin Stone Jun 10 '11 at 09:09
  • Also, maybe this could help: http://stackoverflow.com/questions/4041682/android-opengl-es-framebuffer-objects-rendering-to-texture – Martin Stone Jun 10 '11 at 09:14
  • @Martin Stone - I did check out the link you referenced. I'm trying to pick points in 3D, and obviously can't use depth buffer. Can you explain how to send the depth buffer to the color buffer for use? Thank you! – RedLeader Jul 15 '11 at 22:36