Can't get depth testing to work in OpenGL

前端 未结 2 1233
南笙
南笙 2020-12-06 18:12

I use SFML to create the window.

In this screenshot the cube should be behind the pyramid but it just doesn\'t work.

2条回答
  •  不知归路
    2020-12-06 18:44

    Your code looks okay. I suspect that your window simply does not have a depth buffer. You're using sf::RenderWindow, whose documentation says (emphasis mine):

    Simple wrapper for sf::Window that allows easy 2D rendering.

    I don't know SFML, but this tutorial suggests to create your window like this:

    sf::WindowSettings Settings;
    Settings.DepthBits         = 24; // Request a 24 bits depth buffer
    Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
    Settings.AntialiasingLevel = 2;  // Request 2 levels of antialiasing
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML OpenGL", sf::Style::Close, Settings);
    

    You could set StencilBits and AntialiasingLevel to 0 since this example doesn't need them.

提交回复
热议问题