|Tutorial - Tripple-Buffering|
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
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);
memcpy(VIDEO_ADDRESS, scr, 320 * 200);
// Free the offscreen buffers
// 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.
put_pixel_db(1, 1, 14, scr);
Turbo C - tribuf.zip
|User Contributed Comments(1)|
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
Use the comment system decently.
Post your comment: