简体   繁体   中英

glReadPixels(Depth_Component) not working in Android OpenGL ES20

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM