PDA

View Full Version : OpenGL: Renderbuffer, depth buffer



letslearn
03-10-2012, 02:52 PM
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?).

letslearn
03-10-2012, 04:23 PM
Never mind, my z-buffer is just backwards.