PDA

View Full Version : Depth test not working



esapir
02-28-2014, 03:22 AM
I am using OpenGL ES 2.0 on iOS. I enabled DEPTH_TEST, but still object that should be hidden are rendered.
See screenshots:

http://postimg.org/image/9kp5ltcx7/50d44327/
http://postimg.org/image/t70ga5kw7/

In the seconds image, the green rectangle should be hidden by the red rectangle.
I use the following code in my rendering:

glClearColor(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_DEPTH_TEST | GL_CULL_FACE);

What i could miss?

Agent D
02-28-2014, 08:50 AM
glEnable(GL_DEPTH_TEST | GL_CULL_FACE);

This is garbage. The constants GL_DEPTH_TEST (0x0B71) and GL_CULL_FACE (0x0B44) are not flags (GL_COLOR_BUFFER_BIT and GL_DEPTH_BUFFER_BIT are, hence the _BIT).
You have to call glEnable(GL_DEPTH_TEST) and glEnable(GL_CULL_FACE) seperately.

esapir
02-28-2014, 11:52 AM
This is garbage. The constants GL_DEPTH_TEST (0x0B71) and GL_CULL_FACE (0x0B44) are not flags (GL_COLOR_BUFFER_BIT and GL_DEPTH_BUFFER_BIT are, hence the _BIT).
You have to call glEnable(GL_DEPTH_TEST) and glEnable(GL_CULL_FACE) seperately.

You are correct of course. I had another bug that i fixed after that.
All works well now. thanks!