FramebuffersGL 3.0
glBindFramebuffer
Selects the framebuffer that draw calls render into (and/or read from).
Part of the family glBind*
Signature
void glBindFramebuffer(GLenum target, GLuint framebuffer);
How it works
Everything drawn after this call goes to the bound framebuffer's attachments instead of the screen. Bind 0 to go back to drawing into the window.
A post-processing frame looks like: bind FBO → draw scene → bind 0 → draw a screen quad sampling the FBO's color texture.
Parameters
targetGLenum
Which role to bind for.
Common values
- GL_FRAMEBUFFER
- Both drawing and reading — the usual choice.
- GL_DRAW_FRAMEBUFFER
- Only as a draw destination.
- GL_READ_FRAMEBUFFER
- Only as a read source (glReadPixels, glBlitFramebuffer).
framebufferGLuint
FBO ID, or 0 for the window.
Tips & pitfalls
Remember
glViewportwhen the FBO size differs from the window.Clear the FBO after binding it —
glClearacts on the bound framebuffer.
Example
example.cpp
1glBindFramebuffer(GL_FRAMEBUFFER, sceneFBO);
2glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3drawScene();
4
5glBindFramebuffer(GL_FRAMEBUFFER, 0);
6glBindTexture(GL_TEXTURE_2D, sceneColor);
7drawScreenQuad();