Drawing with Double Buffers

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 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  
    gluPerspective(45, 1.0, 0.1, 100.0); 
    // draw our objects  
    // if we're double-buffering ...  
    if (bDoubleBuffering)  
        // ...draw the copied image to the screen  

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); 
ReleaseDC(hWnd, hdc);