0
\$\begingroup\$

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.

\$\endgroup\$

closed as off-topic by Alexandre Vaillancourt, Pikalek, Gnemlock, Tyyppi_77, Kromster Oct 4 '17 at 20:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem must provide a minimal, complete, verifiable example of the issue so that readers can diagnose it without needing to guess, read all of your code, or engage in extensive back-and-forth dialog. For more information, see this meta thread." – Alexandre Vaillancourt, Pikalek, Gnemlock, Tyyppi_77, Kromster
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Could you show the code that does this? \$\endgroup\$ – Alexandre 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
0
\$\begingroup\$

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.

Example:

// main loop
while(true)
{
    // depth test
    gl_Enable(GL_DEPTH_TEST);

    // render calls...
}
\$\endgroup\$

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