Selected SDL Subroutines
We describe here a few subroutines that you are most likely to use. These will allow you to move sprites around the screen in response to input from mouse and keyboard and thereby create a game. For each routine we provide first the declaration followed by a brief description and examples where necessary. All of the functions that return an integer (except SDL_PollEvent) return -1 on error or 0 on success.
Programs SDL_ImageDemo1 and SDL_ImageDemo2 demonstrate how these routines may be combined to simulate motion. Both programs show for simplicity just a ball rolling down a hillside. We produced the 3D background image using the demo program Voxel, which you download with the Pascal SDL header files. To compile the programs, you need to download and unzip the zip file containing the images and put them in your program folder.
Program SDL_ImageDemo1 uses video memory and, to simulate movement, simply blits all of the background image and then the sprite in its new position. Program SDL_ImageDemo2 uses system memory for the surface, calculates where the sprite is to be positioned, blits the sprite, then restores the rectangle of the background that contained the sprite before blitting the sprite to its next position.
Another difference between the programs is that SDL_ImageDemo1 is a GUI application with no console and uses SDL event handling to quit using the escape key, whereas SDL_ImageDemo2 is a console application with a readln statement to prevent termination. As usual, you should click on the console window then press return to quit.
We simplify the code in these demonstration programs by using most of the functions as procedures; we omit code to use return values to provide error messages when necessary.
Follow the links below to the descriptions and demonstrations of SDL subroutines.