Can't get depth testing to work in OpenGL

前端 未结 2 1236
南笙
南笙 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:43

    In latest version of SFML WindowSettings replaced by ContextSettings. Depth settings can be configured as.

    //Configuring SFML window
    sf::ContextSettings window_settings;
    window_settings.depthBits         = 24; // Request a 24-bit depth buffer
    window_settings.stencilBits       = 8;  // Request a 8 bits stencil buffer
    window_settings.antialiasingLevel = 2;  // Request 2 levels of antialiasing
    
    // Opening SFML window
    sf::Window window(sf::VideoMode(800, 600), "Title", sf::Style::Resize | sf::Style::Close, window_settings);
    glewExperimental = GL_TRUE;
    
    // Initializing glew and openGL
    glewInit();
    glViewport(0, 0, 800, 600);
    
    // Enabling Depth
    glEnable(GL_DEPTH_TEST);
    

提交回复
热议问题