You should be slightly experienced in programming Freepascal. That means you should be familiar with the usual commands of Freepascal. If this is not the case you may have problems because this tutorial deals with the features of the usage of the SDL library.
Now let us begin. There are several units given that can be used. If you want to use SDL library you must include the unit “SDL”. It is needed to initialize any other component of the library. For example there are units called “SDL_audio”, “SDL_video”, “SDL_keyboard” and so on. You can draw conclusions on their meaning from their names. So let us start with the initialization of the SDL video system. The command needed to initialize any component is SDL_INIT(component);
PROGRAM test; USES crt, SDL, SDL_video; BEGIN SDL_INIT(SDL_INIT_VIDEO); END.
Instead of SDL_INIT_VIDEO you could initilize the respective component by using SDL_INIT_AUDIO, SDL_INIT_CDROM, SDL_INIT_JOYSTICK, SDL_INIT_TIMER, SDL_INIT_NOPARACHUTE, SDL_INIT_EVENTTHREAD, SDL_INIT_EVERYTHING. So if you want to use the features provided by the library for sound handling you should init it SDL_INIT_AUDIO. If you use SDL_INIT_EVERYTHING all subsystems are initialized.
There is another very important command: SDL_QUIT. Every program have to be closed by using this command. It cleans up your system! Never fotget it. This procedure ensures that all subsystems initilized get unloaded. There is a corresponding command to unload specific subsystems called SDL_QUITSUBSYSTEM(component).
PROGRAM test; USES crt, SDL, SDL_video; BEGIN SDL_INIT(SDL_INIT_VIDEO); {further code} SDL_QUIT; END.
Well, we have initilized the video subsystem and released it after that. Simple Directmedia Layer deserves its name, isn’t it?