| . |
| Home | Palm Games | Tech Support | Table of Contents | About Us | Email Us |
| Palm Programming |
|
|
| Subroutines and Snippets |
The technique is a simple one to implement involving five steps:
1) create an offscreen window using the WinCreateOffscreenWindow()
2) select the offscreen window as the current window to draw to using WinSetDrawWindow()
3) draw your graphics as you normally would (ie: draw background, add objects, explosions, etc.)
4) select the display screen as the current window to draw to using WinSetDrawWindow()
5) copy the entire screen to the display window using WinCopyRectangle()
subroutines that simplify using double buffered graphics
The color coding used:
light blue = variables, constants, and subroutines names chosen by the programmer
light green = C defined words, Palm API calls, and all else NOT chosen by the programmer
//global variables needed - two WinHandle's (basically pointers to the windows)
WinHandle DisplayWindowH;
WinHandle OffscreenBufferH;
//a subroutine to create the offscreen window (step 1)
//you should call this once at the start of your program
void CreateDoubleBufferWindow()
{
OffscreenBufferH=WinCreateOffscreenWindow(160,160, screenFormat, &err);
}
//a routine to draw to the screen (step 2 and 3)
void DrawScreen()
{
WinSetDrawWindow(OffscreenBufferH);
//
// THIS IS WHERE YOUR CODE GOES TO DRAW TO THE SCREEN
// for an example of a fast bitmap drawing routine refer to our preloading graphics section
// other graphics routines will be found in our subroutines section.
}
//simple routine to refresh the visible screen (step 4 and 5)
void RefreshScreen()
{
RectangleType bounds;
WinSetDrawWindow(DisplayWindowH);
WinGetWindowBounds(&bounds);
WinCopyRectangle (OffscreenBufferH, 0, &bounds, 0, 0, 0);
}
Call the DrawScreen() and RefreshScreen() routines in your eventloop.
| Double buffered graphics for smooth animation |