FramebuffersGL 1.0

glDrawBuffer

Chooses which color buffer of the bound framebuffer receives color output.

Signature

void glDrawBuffer(GLenum buf);

How it works

The main use in modern code is depth-only framebuffers, like a shadow map FBO: there is no color attachment, so you tell OpenGL not to write color at all with GL_NONE. Otherwise the framebuffer would be incomplete.

Parameters

bufGLenum

Target color buffer.

Common values

GL_NONE
Write no color (depth-only passes).
GL_COLOR_ATTACHMENT0 … n
One color attachment of an FBO.
GL_BACK
The window's back buffer (framebuffer 0).

Tips & pitfalls

  • To write to several attachments at once (MRT / G-buffer) use glDrawBuffers with an array.

Example

example.cpp
1glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
2glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowMap, 0);
3glDrawBuffer(GL_NONE);
4glReadBuffer(GL_NONE);
Official Khronos documentation