3

when I enable the lighting in the opengl es, I suddenly found the depth test fails to work. It looks some object is transparent after some rotation. Handle should be invisible from this angle.

I am using glEnable(GL_DEPTH_TEST) in the beginning.

I am using OpenGL ES 2.0

Anything can be wrong?

When I don't use light, everything looks fine.

enter image description here

genpfault
  • 51,148
  • 11
  • 85
  • 139
Adam Lee
  • 24,710
  • 51
  • 156
  • 236

2 Answers2

6

Are you sure you clear the depth buffer before rendering ?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

EDIT :

Also check if you actually activate the depth framebuffer from your windowing API.

If you use GLUT for instance, when calling glutInitDisplayMode your must provide GLUT_DEPTH as parameter.

Oragon Efreet
  • 1,114
  • 1
  • 8
  • 25
  • Yes, I have this before the rendering, but I still get the same result. – Adam Lee Jun 09 '14 at 15:04
  • BTW, I am using VBO to draw. – Adam Lee Jun 09 '14 at 15:04
  • It may be from an user issue like : do you actually activate the depth framebuffer from your windowing API ? If you use GLUT for instance, when calling glutInitDisplayMode your must provide GLUT_DEPTH as parameter. – Oragon Efreet Jun 09 '14 at 15:09
  • @AdamLee: If you render to an FBO, make sure that your FBO has a depth attachment. The depth buffer from your default framebuffer will not be used when rendering to an FBO. You need to create a depth renderbuffer, and attach it to the FBO. – Reto Koradi Jun 09 '14 at 15:37
0

Call this:

gl.glDepthMask( true );

I spent one day to solve this :)

Style-7
  • 985
  • 12
  • 27