Reputation: 2604
I've been switching from freeglut to SFML for OpenGL 3.3 context/window creation. Now when I use freeglut and initialize the display mode with
unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
glutInitDisplayMode (displayMode);
I can simply then type
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
and then depth testing will be enabled. However, in SFML, it's a little more complicated. I won't go into the SFML code, but basically SFML creates a context/window for you. You can specify the number of depth bits and stencil bits, but it seems SFML does not actually allocate the depth buffer and attach it to the default framebuffer.
So how do I actually do this? I'm guessing you have to do something like glGenRenderbuffers
, then glBindRenderbuffer
then glRenderbufferStorage
then glFramebufferRenderbuffer
. The documentation is a little confusing. glRenderbufferStorage
takes an internalformat
parameter, and I'm not really sure how to indicate that I want a 24 bit depth buffer. Also, I'm not really sure how to access the default framebuffer (or are there two default framebuffers, because there's double buffering?).
Upvotes: 1
Views: 1943
Reputation: 6984
In SFML depth can be enabled by ContextSettings
.
//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);
Upvotes: 0
Reputation: 10122
When you create your window, you specify context settings that allow you to define the depth/stencil buffer formats. Something like this:
sf::Window window(sf::VideoMode(1024, 768, 32), "SFML Window", sf::Style::Default, sf::ContextSettings(24, 8, 0, 3, 3));
The above would specify a 24 bit depth buffer with 8 bits of stencil. I'm assuming you're using SFML 2.0 here. Not sure if it's still in beta or is a final release of course.
Upvotes: 3