Tag Archives: sdl 1.2

Chapter 2: First steps using SDL (SDL4FP)

This is an SDL 1.2 chapter. SDL 1.2 is obsolete since it has been replaced by SDL 2.0. Unless you have good reasons to stay here you may prefer to go for the modern SDL 2.0 :-).

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?

Chapter 1: Introduction, installation and configuration (SDL4FP)

This is an SDL 1.2 chapter. SDL 1.2 is obsolete since it has been replaced by SDL 2.0. Unless you have good reasons to stay here you may prefer to go for the modern SDL 2.0 :-).

The introduction is short. SDL library gives you the ability to program powerful applications for many different operating systems (OS) only by learning one set of commands. The SDL library takes on the assignment to translate your commands to the specific OS commands. It’s especially meaningful to use the SDL library if you plan to develop games or similar software.

Now this Chapter concerns on the installation of all necessary software on your system for programming SDL applications with Freepascal under Windows XP (probably this will work for other windows systems as well; please report if you tried out).

First of all, we have to consider which software is needed. We need three different software packages. We need the Freepascal compiler of course. Furthermore we need the SDL library files and finally we need something what translates our pascal programs to the SDL library (written in C/C++). This will be taken on by a few units.

1) Download the latest stable Freepascal compiler (Version 2.0.0). You
get it here: http://www.freepascal.org/
2) Download the latest version of SDL4Freepascal (Version 1.2.0.0). You
get it here: http://sdl4fp.sourceforge.net/
3) Download the latest version of SDL runtime library (Version 1.2.8). You
get it here: http://www.libsdl.org/ (German readers may prefer: http://www.libsdl.de/)

Of course, if you have installed Freepascal already you haven’t to download it again and you can skip step 4.

4) Execute “fpc-2.0.0.i386-win32.exe” to install Freepascal. Let the self-installer create a shortcut on your desktop.
5) Extract “SDL-1.2.8-win32.zip” to get the SDL runtime library. This leads to two extracted files. There is a text file and the very important SDL.dll.
6) Copy those files (especially the SDL.dll!) to your
system32-folder! Usually you find it at “C:\WINDOWS\system32\”.
Don’t confuse it with the similar system-folder. (This works for
WinXP, probably for NT-series and Win2000 as well; if you use Win9x
or WinME you should copy it to system-folder instead of system32-folder)

If it for any reason isn’t possible to copy the files into this folder you later have to have that file into the same folder where the application is. Now you have installed Freepascal and the SDL runtime library on your system. Finally SDL4Freepascal have to be installed.

7) Extract “SDL4Freepascal-1.2.0.0.tar.gz” to get the units and some demo programs. There should be about 20 files and a folder “demos” which contains five more files.
8) Open the folder where you have installed Freepascal (e.g. C:\FPC\)
9) Open the folder “units” (e.g. C:\FPC\units\)
10) Create a new folder called “sdl” (e.g. C:\FPC\units\sdl\)
11) Copy the whole former extracted files (including the folder “demos”) from SDL4Freepascal into the sdl-Folder.

Now the compiler has to be told about where to find the new units.

12) Open the Freepascal IDE (for example by clicking the shortcut on desktop).
13) In the menue choose the following item “Options”. From “Options” choose “Directories…”. Now a window should pop up.
14) The last row is called “Unit directories”. There you should write in the full path to your SDL-units (e.g. C:\FPC\units\sdl). Leave the last backslash out.

Congratulations! You have configured your system for developing SDL applications with Freepascal! Now let’s check if it really was that easy…

15) Open the file “demo02.pp” in demos-folder (e.g. C:\FPC\units\sdl\demos\). Run it.

If you see some cool colourful red and blue lines you have done everything as it has to be done :)! Have fun with your configured system!

For those of you who try running the demo and get an abortion together with a messege saying “exitcode = 309”: You skipped step 6! Did you copy the SDL.dll to your system32- or system-folder respectively? If so and the error still occurs you should copy the SDL.dll into the folder where the demos are placed. Now it should work.

[Downloads transferred from old website]

SDL4Freepascal-1.2.0.0.tar.gz; OUTDATED: SDL4Free Pascal Version 1.2.0.0 (most recent)