The Allegro Wiki is migrating to github at

Difference between revisions of "Double buffering"

From Allegro Wiki
Jump to: navigation, search
m (New category)
Line 34: Line 34:

Revision as of 18:27, July 15, 2007


Double buffering is one of the most basic methods of updating the display. This is often the first buffering technique adopted by new coders to combat flickering.

Double buffering uses a memory bitmap as a buffer to draw onto. The buffer is then drawn onto screen. If the objects were drawn directly to screen, the display could be updated mid-draw leaving some objects out. When the buffer, with all the objects already on it, is drawn onto screen, the new image will be drawn over the old one (screen should not be cleared). If the display gets updated before the drawing is complete, there may be a noticeable shear in the image, but all objects will be drawn. Shearing can be avoided by using vsync.


Double buffering is extremely easy to use. After initializing a graphics mode, you need to create the buffer:

<highlightSyntax language="c"> BITMAP *buffer;

buffer = create_bitmap(SCREEN_W, SCREEN_H); clear_bitmap(buffer); </highlightSyntax>

Then, do all your drawing onto buffer. Finally, you have to blit the buffer to screen:

<highlightSyntax language="c"> //In this example a sigle pixel is being drawn putpixel(buffer, pixel_x, pixel_y, pixel_color);

//After everything has been drawn onto buffer, buffer needs to be drawn onto screen blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); </highlightSyntax>


  • Double buffering uses only memory bitmaps, so you can safely use transcluency with it.

See Also

<tasks> [ ] Write an example code snippet, like the one for page flipping. </tasks>