Getting Started with SDL

We have used the Freepascal meets SDL site, our first recommended resource, to provide these sections to help you to start using SDL.

The following applies to Microsoft Windows operating systems. We begin by giving instructions to write and run a limited range of programs using some of the parts of SDL and then provide guidance on extending the functionality.

You need to download SDL.dll, which is available currently in a zip file.

If you have the necessary access rights, put SDL.dll in your system folder (where there may be around 5000 .dll files already!). The pathname of the system folder is likely to be c:\windows\system32. You can alternatively put SDL.dll in the folder of each program that uses it, if, for example, you are working on a networked computer and do not have the right to add files to the system folder.

In order for you to use SDL.dll, your compiler needs access to sdl.pas and jedi-sdl.inc. You can put these in your program folder, or put them in a fixed location and add the path of their containing folder to the list of paths known to the compiler. To achieve this in Lazarus:

  1. Select from the menu Project > Compiler Options …
  2. Add the path of sdl.pas and jedi-sdl.inc to Other Unit Files as shown below.
Other Unit Files

Other Unit Files

There is a beta installer for Delphi. A folder structure containing source files such as sdl.pas is copied to a location such as C:\Program Files\Jedi-SDL full and the compiler settings are added automatically. To check the settings:

  1. Select from the menu Tools > Environment Options …
  2. Select the Library tag
  3. Click on the ellipsis alongside the Library path.

We obtained the following using Delphi 7.

Paths

Paths

You can use program PutPixelDemo to test this basic set-up in both Lazarus and Delphi.

There are many other files you can use to extend the functionality. These are tabulated on the SDL Meets Pascal site. You can use other dynamic linked libraries such as SDL_mixer.dll, smpeg.dll, and SDL_image.dll in the same way that you have used SDL.dll. You can use other header files such as sdl_mixer.pas, smpeg.pas and sdl_image.pas in the way that you used sdl.pas. To test your set-up for these additional units, you could try to compile and run program JEDISDLAliens in the folder Demos\2D\Aliens of your header file download. This should compile in Delphi after you have performed the automatic set-up and added the above dynamic link libraries either to the program folder or to your system folder.

In order to run program JEDISDLAliens in Lazarus you need to add the paths separated by a semicolon to the list of unit files e.g. C:\Program Files\JEDI-SDL Full\SDL\Pas\;C:\Program Files\JEDI-SDL Full\SDL_mixer\Pas\;C:\Program Files\JEDI-SDL Full\smpeg\Pas\;C:\Program Files\JEDI-SDL Full\SDL_image\Pas\

In addition, you need a copy of jedi-sdl.inc in each of the three additional Pas folders that you have added to the unit file path list.

Programming - a skill for life!

Using SDL to write games in Pascal