void glDrawBuffer(GLenum mode);

Specify, Select which color buffers are to be drawn into.

OpenGL stores and manipulates pixel data in a framebuffer. The framebuffer consists of a set of logical buffers: color, depth, accumulation, and stencil buffers. The color buffer itself consists of a set of logical buffers; this set can include a front-left, a front-right, a back-left, a back-right, and some number of auxiliary buffers.

Double buffering is a technique in which an application draws pixels to an off-screen buffer, and then, when that image is ready for display, copies the contents of the off-screen buffer to an on-screen buffer. Double buffering enables smooth image changes, which are especially important for animated images.

Mode GL_BACK can specify back buffer to be written.

Two color buffers are available to applications that use double buffering: a front buffer and a back buffer. By default, drawing commands are directed to the back buffer (the off-screen buffer), while the front buffer is displayed on the screen. When the off-screen buffer is ready for display, you call SwapBuffers, and OpenGL copies the contents of the off-screen buffer to the on-screen buffer.

Buffers in OpenGL

Buffer objects are handles to OpenGL-managed memory. There are many kinds of buffers in OpenGL. The most frequently used is color buffers.

Color Buffer

The Color Buffer store the color for each pixels of the current frame. This buffer is what you see

The color is in RGBA mode ie Red Green Blue and Alpha.

The 3 first components (RGB) can be considered as the color of the pixel. The Alpha value can be considered as the opacity or transparency of the pixel. Alpha component of the color is associated with blending.

Depth Buffer

The Depth Buffer holds the depth of each pixels of the frame. It is also called z buffer.

Depth buffer is associated with the Depth Test. For each pixel drawn, the Depth Test compare the current depth stored in the depth buffer with the depth of the new pixel to draw. Depending on the result of the test, the pixel is drawn or not.

We usually use the depth buffer to draw nearest pixels, pixels behind are not drawn.

Stencil Buffer

The Stencil Buffer can be used for restricting drawing area.

This buffer store a value associated to each pixels. Typically, we begin to draw a shape and tells to set 1 where pixels (of this shape) are drawn. Then, we make read only this buffer and tells we only want to draw where value is 1. Following objects will only be drawn in the corrsponding region of '1'.

Stencil buffer is usually used in multipass rendering to achieve particular effects

Accumulation Buffer

Accumulation Buffer store RGBA color like for Color Buffer.

This buffer is used for scene antialiazing, motion blur (motion blur effect can be achieved with blending),

Because glDrawBuffer is about color buffers, so in this post we focused on the color buffers.

In the simplest case, frame buffer is color buffer, in complex system such as D3D and OpenGL, frame buffer holds far more information such as depth information. Frame buffer consist of multiple buffers, some of them are color buffers that hold the colored pixel that are displayed.


glDrawBuffer Reference doc