Double buffering is a technique used to eliminate a nasty phenomenon called 'flickering'.
Flickering occurs when you draw stuff to the screen at the same time as it's being displayed, and usually shows up in the form of 'tears' (the paper kind!) somewhere down the screen.The basic idea behind double buffering is to eliminate flickering by NOT drawing to the VISIBLE screen.
Instead, you draw to what's known as the 'back buffer'. The back buffer is the same size as the screen - and you draw to it exactly the same way you draw to the screen, the only difference is it isn't the visible screen!
Also, to make things nice and tidy for us programmers, the visible screen is usually refered to as the 'front buffer'.
Eventually, of course, you want the person playing your game to actually see what you've been drawing, and to do this you use the 'Flip' command. 'Flip' causes the front and back buffers to be flipped, or 'swapped', this has the effect of revealing all the cool stuff you've been drawing to the back buffer!
Graphics cards can achieve this flipping effect very quickly, so double buffering is a very cheap'n'cheerful way to eliminate flickering from your games.
If you're finding this confusing, here's another way of thinking about it...
Imagine you have two screens on your desk - one in front of the other so that you can only see one of the screens. Now imagine drawing a lot of stuff to the screen at the back. The user won't see any of this drawing activity, as they can only see the front screen. Now imagine that you quickly swap the 2 screens, so that the screen that was at the back is now at the front.
Bingo! That's double buffering!
To use double buffering, you'll need 2 commands - 'SetBuffer' and 'Flip'.
SetBuffer is used to tell Blitz which buffer you're drawing to - the front buffer or the back buffer.
Flip is used to do the swapping of the front and back buffers. Here's an example:
Graphics 640,480
SetBuffer FrontBuffer() ;draw to the front bufffer...
Text 0,0,"This is on the Front Buffer"
SetBuffer BackBuffer() ;draw to the back buffer...
Text 0,0,"This is on the Back Buffer"
While Not KeyDown(1) ;ESC to quit!
WaitKey
Flip ;swap front and back buffers
WendIf you run this, the first thing you'll see will be 'This is on the front buffer', now each time you hit a key, the front and back buffers will be swapped, so you'll get alternating messages.
To use double buffering in games is very simple.
You typically do ALL your drawing to the back buffer, and use flip each time you've finished.
A typical double buffered game loop looks like this...Graphics 640,480
SetBuffer BackBuffer()
While game_on
Cls ;clear the buffer
DrawStuff() ;draw everything
Flip ;reveal the back buffer!
Wend