1

I tried to use the glDepthFunc in OpenGL ES 2.0 (at PC with emulator) and i don't understand the behavior.

In init function i only call define these values:

glClearDepthf( 0.5f );
glClearColor ( 1.0f, 0.0f, 0.0f, 0.0f );

And in drawing function this code:

glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable( GL_DEPTH_TEST );
glDepthFunc(GL_LEQUAL);
glUniform4fv(unifColor, 1, verColor);
glDrawArrays ( GL_TRIANGLE_FAN, 0, 4 );
eglSwapBuffers

I'm drawing a green square (half of the screen size). When the z value of the drawn square is 0.5.

I expect that the depth test will be TRUE and i'll see the green square drawn, but i see only red screen (the color that is used in clear color). When i define the clear depth value to be 1.0 i receive the expected behaviour: grren squar on red screen, so i think the depth is used as needed (all the initialzed defines for depth).

What can be the problem?

Thanks for your help

1 Answer 1

0

There are some things that could go wrong. There might be some precision issues. However, I have some guess here:

I'm drawing a green square (half of the screen size). When the z value of the drawn square is 0.5.

Wrriting somehting like (x, y, 0.5, 1) to gl_Position will not result in a window space z value of 0.5, but in 0.75. The NDC coords of [-1,1] are mapped to the depth range (by default [0,1]). Try drawing at z=0 to get a window space z value of 0.5 (and be prepared for additional precision issues). All this assumes that there is no further transformation, especially no perspective, of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.