Code Snippets
Code Samples

The Blog
Our Projects

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

Tutorial - Tripple-Buffering
Category:DOS Graphics
Uploaded at:28-May-03
Well well well, did you guess what Triple-Buffering stands for already and why we use it?
Hmmm one offscreen (buffer) for background, another buffer for foreground and one is the Video Memory as usual.
If you have no $^@$ing idea what I'm talking about then read this.

OK you smart ass, you ask why you need another offscreen huh?
Well ofcourse you can handle well without it, but it makes life easier and your program faster. Think that you make a game that has a static background image (or one which rarely changes), then instead of loading the image every frame and draw it, you will just load it once and draw it once on the background offscreen. Then every frame you copy the background onto the foreground, draw the foreground stuff (such as: Players, Bullets, Effects.. bla bla). And then draw the foreground buffer onto the screen. That it is.

In the source code of this tutorial you will find a nice example of using Triple-Buffering.. Check it out... It took me around 30 mins to write it... but the damn background image took more time to draw :)

// Pointers to the buffers.
unsigned char *scr = NULL, *bkg = NULL;

// Allocate memory for the buffers
int init_virscr()
 scr = (unsigned char *)malloc(320 * 200);
 if (src == NULL) return(0);
 bkg = (unsigned char *)malloc(320 * 200);
 if (bkg == NULL)

// Draw a pixel on a given buffer
void plotpixel_db(int x, int y, unsigned char co, 
                  unsigned char *buf)
 buf[(y << 6) + (y << 8) + x] = col;

void copy_screen(unsigned char *dst, unsigned char *src)
 memcpy(dst, src, 320 * 200);

void drawscreen_db()
 memcpy(VIDEO_ADDRESS, scr, 320 * 200);

// Free the offscreen buffers
void free_virscr()

// Usage of the Triple-Buffering:
// (Hey the source is really really cool!! You'll like it)
// Draw a pixel as the background screen :) yak
putpixel_db(0, 0, 10, bkg);
 // Copy the background onto our foreground offscreen.
 // Notice we don't need to clear the screen.
 copy_screen(scr, bkg);
 put_pixel_db(1, 1, 14, scr);

Source Code:
Turbo C - tribuf.zip

User Contributed Comments(1)
 [1] Gaebu rider | 2013-08-29 02:49:08

Great tutorial. This was the only one I found on the internet about tripple buffering. ;)
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
::Top 5 Tutorials::
Embedded Python[106929]
2D Rotated Rectangles Collision Detection[80070]
Keyboard Hook[69210]
HTTP Proxy[36376]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10648]
PS2 Mouse Driver[6131]
Wave Format Player[5015]
Reading FAT12[4902]

All rights reserved to RageStorm © 2009