Search code examples
copenglsfml

In OpenGL, with depth test enabled, still find some triangles overlaps wrongly


I rotate the box around X axis

those are images taken when running my code:

example1

example2

example3 a plane has lost

I used glEnable(GL_DEPTH_TEST), and glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)before drawing.

why?


Solution

  • Your window (default framebuffer) doesn't have a depth buffer at all. You have to setup a OpenGL window with a depth buffer by using the sf::ContextSettings class.

    See Using OpenGL in a SFML window:

    ContextSettings settings;
    settings.depthBits = 24;