I am drawing two cubes, first a red one and then a green one in front of the red one. When I rotate the camera I can see the green cube through the red cube.

green cube behind red cube

I have enabled depth test and I clear depth buffer. I'm using OpenGL 4.4 core profile and a simple diffuse shader by the way.

| improve this question | | | | |
  • \$\begingroup\$ Could you show the code that does this? \$\endgroup\$ – Vaillancourt Sep 22 '17 at 19:06
  • \$\begingroup\$ Unfortunately it's encapsulated in several classes. It's a simple vertex array and element draw call. \$\endgroup\$ – MahanGM Sep 22 '17 at 19:11
  • \$\begingroup\$ "I have enabled depth test and I clear depth buffer." Are you sure? \$\endgroup\$ – tkausl Sep 22 '17 at 19:13
  • \$\begingroup\$ I am sorry it was totally me. I was setting depth test only at the begining. \$\endgroup\$ – MahanGM Sep 22 '17 at 19:23
  • 1
    \$\begingroup\$ Please post your solution as an answer to the question, and accept it to mark your question as solved. \$\endgroup\$ – Tyyppi_77 Sep 30 '17 at 7:13

I was using gl_Enable(GL_DEPTH_TEST); only at the beginning of my render process outside of the main loop so then I realized I should set this render state every frame before my render calls so I did it.


// main loop
    // depth test

    // render calls...
| improve this answer | | | | |

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