All posts by Matthias

A Custom Mouse Cursor

Last updated on September 21st, 2019

Any good game has a custom mouse cursor. You may think it would be a good idea to have a SDL2 surface or SDL2 texture and render it as any other sprite right at the mouse position to simulate a mouse cursor. DO NOT do this! The mouse cursor is handled separatly from the other rendering to have it smooth and working in critical situations. 

The following code shows how to set up a custom mouse cursor with SDL2 the correct way.

To have a custom mouse cursor we need a variable of type PSDL_Cursor. We call it “sdlMouseCursor” here.

The result looks like this:

Custom Mouse Cursor in SDL2
Creative Commons License This image by is licensed under a Creative Commons Attribution 4.0 International License.
The blue cross with the yellow outline is the mouse cursor on the grey canvas/window. 

This is the interesting part of the code with regard to creating a custom mouse cursor. The cursor’s image is defined by a SDL surface. We create the SDL surface as known from a previous chapter from a png image file to “sdlSurface1” here.

The custom mouse cursor is created by the following function, which returns nil on error.

It needs the surface to use as cursor image and two coordinates (hot_x/hot_y) as arguments. They determine where the actual hitting point for this cursor is. Since the example cursor image is of dimensions 16×16 px and represents a cross, the “hot” (hitting) coordiates are (8/8), hence the cross’ center is used for hitting a button or something. In contrast you may imagine a typical arrow shaped mouse cursor, where the hitting point has to be adjusted to be right on the tip of the arrow in the arrow’s image.

If the cursor creation has been successful, it is necessary to set it to be the actual cursor. You may have created many different cursors, so tell SDL which one to use by the following procedure.

The remaining part of the code is just rendering a 500 by 500 pixels window with a grey (128, 128, 128) background that is updated as long as no mouse button has been pressed.

Finally do not forget to free the mouse cursor by SDL_FreeCursor(mouse cursor) as shown.

← previous Chapter | next Chapter →

Which SDL2 unit to choose?

Last updated on October 6th, 2019

Right now I’m aware of these translation projects that provide SDL2 units (if you know a further one, let me know):

Tim Blume's SDL 2.0 units Pure translation of SDL 2.0 source files. The original, modular structure of the header files is preserved, so the SDL2.pas is composed of many include files. Translations of SDL2_mixer, SDL2_ttf and SDL2_image are available, SDL_net seems to be missing so far. It provides MacOS X support.
p_daniel's (or danpla's or de-signer) SDL 2.0 units Pure translation of the SDL 2.0 source files. All the header files of the original SDL 2.0 source code are combined into one large SDL2.pas (similar to JEDI-SDL's SDL.pas for SDL). Translations of SDL2_mixer, SDL2_ttf, SDL2_image and SDL2_net are available. The MacOS X support is unproven.
Imants Gulis' SDL 2.0 units Heavily modified SDL 2.0 units to allow for dynamic loading of the library.
Bare Game Library Bare Game is a game library which is put on top of the SDL2 library. It also allows for easy combination of SDL2 with Lazarus, which is a great plus. [Official website ( is down, is the project dead?]

Now we go for a detailed discussion of them.

Modified header translations

Well, the Bare Game Library is a great project and I like the idea to provide an easy-to-use game development library  very much but it isn’t suitable to learn pure SDL 2.0. Many functions are wrapped by new function names, you would learn much about the usage of Bare Game, fewer about SDL 2.0 itself. Also, the ease of use is traded for flexibility, e.g. there is just support for Windows and Linux, no Mac support, and you are more or less forced to use Lazarus IDE (which is an excellent choice, no question!) but for some reason you might not want to use Lazarus. The usage of libraries always trades ease for flexibility. And finally you are dependent upon a second project. If SDL 2.0 is updated, will Bare Game have updates, too? Bare Game is a great project at all, but for learning SDL 2.0 and if you keep the downsides in mind, it is not the best choice here.

Imant’s Gulis units allow for dynamic loading of SDL 2.0, hence your application decides during run-time if SDL 2.0 has to be loaded. This led to heavily modified unit files compared to the original header files. Also it is expected to use Lazarus. Although there are numerous cases where dynamic loading can be a great plus, for the tutorial and a wide variety of applications this is not necessary.

Pure header translations

The unmodified header translations of the original SDL 2.0 headers is the best choice when it comes to learning SDL 2.0.

The beauty of p_daniel’s SDL 2.0 units is the fact that there are exactly five files you need. They contain all the translations for basic SDL 2.0 and the official extensions SDL2_mixer, SDL2_ttf, SDL2_image and SDL_net. Unfortunately, the original comments are cut out. This is a major drawback to my mind. Sometimes you need just a quick look at the implementation of a function in the source to get how it works or what is wrong. Also the MaxOS support is unproven.

In contrast Tim Blume’s SDL 2.0 units kept the comments. The unit names differ slightly from the original names (e.g. SDL_audio.h got instead of ), which I don’t like, but it is acceptable. This allows for a better understanding in how SDL 2.0 works. Also it allows for better flexibility with regards to later projects.


This said, to my mind, the best choice to start with SDL 2.0 and Free Pascal: Go for Tim Blume’s SDL 2.0 units. For other purposes, other units may be the better choice.

Android News Cover Image

About SDL2, Free Pascal and… Android

Since the rise of SmartPhones, many wonder if Free Pascal/SDL2 development  is possible for them, too. The good news is, yes it is possible! The bad news is, it is kind of toilsome to set up a development environment for Android (one of the two major operating systems of many SmartPhones).

Imants Gulbis informed me that he set up a Lazarus package (LazSDL2Design) which makes development of SDL2 applications with Free Pascal for Android fairly simple and integrates with the Lazarus IDE. Check out the instructions to make Lazarus/SDL2 ready for Android. The LazSDL2Design package relies on an own translation of SDL2 headers (LazSDL2) by him.

I put together some useful resources for Android development in the FAQ.

Thanks to reader Paul for letting me know about an unclear statement in Chapter 8 Part 1.

The website uses HTTPS now.

Android, SDL2 and Pascal?

Recently, I get more and more questions and requests regarding the development of Android applications with SDL2 and Free Pascal. Since I’m not planning to do a tutorial chapter on this in the near future, I would like to share some resources which may help you to set your system up. – Contact me, if you are interested in sharing a tutorial on how to set up a SDL2/Free Pascal/Android development environment (or if you know further resources which should be covered here).

  1. This step by step tutorial describes very detailed the setup of a SDL2/Android development environment under Window, though it aims for C++ development rather than Pascal development:

  1.  This is a short introduction how to setup your system and Lazarus (Free Pascal) to develop Android Apps:

  1. These links lead you to a Lazarus package that allows for SDL2 and simple Android development and a configuration of it:




Linux Tutorial News Cover Image

New Linux Installation Chapter

A new Chapter 2 has been added. In contrast to the classical Chapter 2 which explains the installation of SDL2 and Free Pascal for the Windows operating system, the new Chapter 2 explains the installation and configuration of SDL2 and Free Pascal/Lazarus in Linux. Initially I was trying to check for some troubles which got mentioned. Finally I ended up with a short, new installation chapter. A few minor changes have been added to the other chapters which are basically hints for Linux users.

A few new great and interesting Free Pascal/SDL projects have been added to the project page. These are namely GearHead: Arena, GearHead 2, Dungeon Monkey Unlimited, Monsterland and DoomRL. The former three are open source by the way.


Short description

DoomRL is based on ID’s famous Doom game. The RL means roguelike.

Showcase and Basic Data

Developer granted permission to use these screenshots.

  • Project name: DoomRL (a.k.a Doom, the Roguelike)
  • Author: Kornel Kisielewicz (Code/Design), Derek Yu (art)
  • Latest version:
  • Release date: 2001 (initial version), 19 March 2013 (latest version)
  • Pascal compiler: FPC 3.0
  • SDL Version: 1.2
  • Further libraries: Lua, OpenGL, FMOD
  • License: Donationware
  • Open source: no
  • Official website:

Interview with Kornel Kisielewicz

Why did you decide to choose Pascal as a programming language and SDL as a library for your projects?

Kornel Kisielewicz: Pascal was my first language, and in those days C++ was quite messy. I liked the clean syntax of Pascal and it’s default strong type system. SDL was a no brainer, we wanted a platform independent layer for OpenGL context creation and Input handling, and SDL was the only reasonable choice in that regard at the time.

What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides your own, of course :-D)?

Kornel Kisielewicz: I have been out of touch with the Pascal scene for a long time now.

Are there any new projects planned?

Kornel Kisielewicz: We’re currently working on Jupiter Hell, a spiritual successor to DoomRL, but it’s in full 3d, and written in C++.

Chapter 2 – Installation and Configuration (Linux version)

Last updated on April 7th, 2020

This chapter illustrates quickly how to set up a Free Pascal and SDL2 development environment within a few minutes under Linux.

Attention: The following instruction particularly work for many Debian and Ubuntu based Linux distributions (like Linux Mint used here). In general it outlines the way to go, though.

The distribution and software I used:

  • Linux Distribution: Linux Mint 19.3 (Ubuntu/Debian based)
  • Desktop: Cinnamon Desktop
  • Lazarus 2.0.6 (installed from .deb file)
  • FPC 3.0.4 (installed from .deb file)
  • FPC 3.0.4 Source Code (installed from .deb file)
  • Tim Blume’s SDL2 units (header translation)
  • SDL2, SDL2_image, SDL2_ttf shared object files (from distro’s package manager)

Download and install FPC, FPC sourc code and Lazarus

The first step is to install the Free Pascal compiler (version 3.0.4 or higher), the Compiler’s source code (same version as the compiler) and the Lazarurs IDE (version 2.0.6 or higher). To get the most recent, stable environment, download these three files from the official Lazarus website:

Important: Do not intermix FPC or Lazarus installs from the package manager. This will lead to troubles because these installs are not compatible. Purge any of these installs. Use, e.g.:

Choose one of the “Linux DEB Releases” according to your system (32 bit or 64 bit). Most probably your running on a 64 bit system, which is the standard case for Linux.

In case of a 64 bit system download these three files:

  • fpc-laz_3.0.4-1_amd64.deb
  • fpc-src_3.0.4-2_amd64.deb
  • lazarus-project_2.0.6-0_amd64.deb

The download page looks somewhat like this:

Install Packages for Linux FPC SDL2 environment with Lazarus
SourceForge download page for all three files necessary. The original description is kept in the image.

If you downloaded these three files successfully, you run them in the same order! First FPC, then FPC’s sources and finally Lazarus.

If everything went right, Lazarus can be started up by typing “startlazarus” in the terminal or by finding the program in the application menue.

Start up Lazarus the first time

On start up of Lazarus the directories for FPC and the FPC source code were found and set already. As a hint I show where these are located on my system:

  • FPC: /usr/bin/fpc
  • FPC Source code: /usr/share/fpcsrc/3.0.4 (because $(FPCVER) equals the version number, see screenshot)

The configurations screen may look somewhat different to the screen of the following screenshot, but that is because the screenshot is outdated a bit.

Path FPC and FPC Source code
Either detected automatically or can be manually added by Tools > Options …

Before proceeding, my suggestion is to simply compile the project (press F9 in Lazarus) which is presented to you. It should compile and show the form.

Get the SDL2 units

Get the latest version of the translated SDL2 units.

Download SDL2 units on GitHub
Choose the master branch (1), click on “Clone or download” (2) and click on Download ZIP (3).

Make sure you have the master branch chosen and then click on “Clone or download”, then “Download ZIP”.

After extracting the ZIP file I suggest to rename the new folder into “sdl2” or “SDL2” and place it at any location, perhaps your development folder, e.g.:

  • ~/projects/sdl2 (a.k.a /home/[username]/projects/sdl2)
  • (DO NOT use the suggested folder in the screenshot)
Path to SDL2 units
This folder is suggested as a place for the SDL2 units (DO NOT use this folder!). By the way, “Chap7” is just a random name for this project and you may have anything else there instead (I was trying out Chapter 7 tutorial code).

Get the SDL2 shared object files

If you are looking for the most recent pre-compiled SDL2 dynamic link library files (e.g. on the official SDL2 website, you just find a remark that reads like this:

Please contact your distribution maintainer for updates.

Since SDL2 is very widespread it is very likely that your distribution maintainer already included the files.

Find SDL2 and all necessary libraries in your distribution’s package manager, here it is the synaptic package manager. Look for libsdl and install every package shown in the screenshot:

Synaptic package manager shows installed sdl2 shared object packages.

Find all necessary libraries and install them. These you should install:

  • libsdl2
  • libsdl2-dev
  • libsdl2-gfx
  • libsdl2-gfx-dev
  • libsdl2-image
  • libsdl2-image-dev
  • libsdl2-mixer
  • libsdl2-mixer-dev
  • libsdl2-net
  • libsdl2-net-dev
  • libsdl2-ttf
  • libsdl2-ttf-dev

The dev-packages are necessary to compile sdl2 applications. The other packages are necessary to run sdl2 applications.

The version of these libraries does not necessarily need to be the most recent unfortunately. If you really need the most recent versions here, you may try to contact the maintainer to ask to update the version.

Congratulation! After that, everything should run smoothly :-)!

← Chapter 1 | Chapter 3 →


Short description

A commercial action shooter with appealing DOS-like appearance by developer Second Variety Games.

Showcase and Basic Data

Developer granted permission to use these screenshots.

  • Project name: Monsterland
  • Author: Second Variety Games
  • Latest version: 1.15
  • Release date: 12/14/2015
  • Pascal compiler: Free Pascal 3.0.0
  • SDL Version: 1.2
  • Further libraries: sdl_image, sdl_mixer
  • License: commercial product
  • Open source: no
  • Official website: none except Steam page:

Interview with Aleksey from Second Variety Games

Could you please give a short description of Monsterland for those who have never heard of it?

Aleksey: Monsterland is a 2D realtime shooter portrayed entirely through ASCII characters. This includes blood, lighting, particles, etc. Its only gameplay mode is a 3-hour story campaign, which has voiceovers, triggers and scripted sequences. The gameplay of Monsterland was heavily influenced by original Doom games (1 and 2).

Why did you decide to choose Pascal as a programming language and SDL as a library for your projects?

Aleksey: Pascal is an underrated, well-rounded programming language. It has good diagnostics and strict syntax, which removes ambiguity from error messages. It also helps that I was first introduced to it in 1992.

SDL was chosen because I’ve also been writing an engine tied to DirectX, and given where Windows is heading, it was a mistake I didn’t want to repeat. SDL 1.2 didn’t have accelerated 2D though, so I had to do it via OpenGL manually.

What do you think is the most interesting Pascal/SDL/SDL2 project out there (besides your own, of course :-D)?

Aleksey: If Dwarf Fortress still used Pascal, I’d name that. Otherwise, DoomRL I guess.

Are there any further steps planned for the Monsterland series? What will they be?

Aleksey: Aw, you flatter, but Monsterland will not be continued.

Are there any new projects planned?

Aleksey: I’m starting to work on a new type of IF (interactive fiction) game. I clearly have an obsession with text visuals.

There’s also the ambitious isometric RPG I’ve been writing in C for years, the “magnum opus”, but it’s too ambitious at the moment, even though a lot of work has been done. I wish I wrote it in Pascal instead – it would’ve been easier to debug.


Dungeon Monkey Unlimited

Short description

Dungeon Monkey Unlimited is a turn-based, rouge-like role-playing game where you can explore ancient worlds with benign graphics.

Showcase and Basic Data

Developer granted permission to use these screenshots.

  • Project name: Dungeon Monkey Unlimited
  • Author: Joseph Hewitt; graphics obtained from the David Gervais and rltiles sets.
  • Latest version: 1.001
  • Release date: September 20 2010.
  • Pascal compiler: Free Pascal
  • SDL Version: 1.2
  • Further libraries: Only those that come with the FPC compiler
  • License: GPL
  • Open source: Yes
  • Official website:

GearHead 2

Short description

GearHead 2, successor of GearHead: Arena, is a turn-based, rouge-like role-playing game where you can explore futuristic worlds with benign graphics.

Showcase and Basic Data

(no showcase screenshots provided)

  • Project name: GearHead 2
  • Author: Joseph Hewitt, plus the work of several contributors
  • Latest version: 0.628
  • Release date: The first public release was August 23 2005; the most recent was June 1 2010. After I’ve updated GearHead-1 to my satisfaction I plan to do some revisions to this one as well.
  • Pascal compiler: Free Pascal
  • SDL Version: 1.2
  • Further libraries: Only those that come with the FPC compiler
  • License: LGPL
  • Open source: Yes
  • Official website: