Double buffers smooth the transition between one image and another on the screen. Swapping buffers typically comes at the end of a sequence of drawing commands. By default, the Microsoft implementation of OpenGL in Windows NT and Windows 95 draws to the off-screen buffer; when drawing is complete, you call the SwapBuffers function to copy the off-screen buffer to the on-screen buffer. The following code sample prepares to draw, calls a drawing function, and then copies the completed image on to the screen if double buffering is available.
void myRedraw(void)
{
// set up for drawing commands
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 1.0, 0.1, 100.0);
// draw our objects
myDrawAllObjects(GL_FALSE);
// if we're double-buffering ...
if (bDoubleBuffering)
// ...draw the copied image to the screen
SwapBuffers(hdc);
}
The following code sample obtains a window device context, renders a scene, copies the image to the screen (to show the rendering), and then releases the device context.
hdc = GetDC(hwnd);
mySceneRenderingFunction();
SwapBuffers(hdc);
ReleaseDC(hWnd, hdc);