What is SDL2?
SDL2 (Simple DirectMedia Layer 2) is a cross-platform development library designed to provide low-level access to:
- Audio
- Keyboard
- Mouse
- Joystick
- Graphics hardware via OpenGL and Direct3D
It is mainly used for game development, multimedia applications, and real-time simulations.
Key Features of SDL2
- Cross-platform: Works on Windows, macOS, Linux, iOS, Android, and more.
- Written in C, but usable in C++, and has bindings for many other languages (Python, Rust, etc.).
- Supports 2D rendering, but can also be combined with OpenGL or Vulkan for 3D rendering.
- Manages window creation, input events, timing, and threading in a unified way.
Games that use SDL2
Commercial / Popular Games
- Valve’s Source Engine games (e.g., Half-Life 2, Portal) — use SDL2 on Linux/macOS.
- Doom 3: BFG Edition — open-source version uses SDL2.
- Unreal Tournament (classic) — community ports and updates use SDL2.
- Hollow Knight (Linux version) — uses SDL2 for platform compatibility.
- Factorio — cross-platform game built using SDL2.
- Celeste (Linux/macOS versions) — platformer that uses SDL2.
- Stardew Valley (Linux port) — uses SDL2.
Open Source / Indie Games
- OpenTTD — transport tycoon clone; migrated to SDL2.
- The Battle for Wesnoth — turn-based strategy game.
- Cave Story NX — SDL2-based port of the cult indie game Cave Story.
- SuperTux — 2D platformer in the spirit of Super Mario.
- Dwarf Fortress (Premium version) — now uses SDL2 for graphics and input.
Here you can find a collection of SDL2 tutorials ranging from beginning to expert level. SDL2 is nice, because it’s multiplatforms, and it can use DirectX or OpenGL. I tried to focus on original content you usually don’t found elsewhere. Most of my tutorial are code heavy, I tried to used an example to have something working at the end of the tutorial.
For my part, I have used SDL2 to make a simple engine for my first commercial game Hope :
These tutorials use the version 2 of SDL2 not the first version which is only used in legacy code.
For the game editor I have used SFML which is simpler to set up than SDL2.
Basics SDL2 tutorials
The tutorials here show the basics modules of SDL, to make a full game you will probably need to go implements the systems described in the advanced tutorials.
Start with them it’s easier to understand the basic concept on some simple example 😉
- Installation of SDL2 on Windows (Visual Studio 2017)
- Installation of SDL2 on Linux
- Static build of SDL2 on Windows
- Static build of SDL2 on MacOS
- Display an image with SDL_image
- Make a health bar with SDL2
- Displaying unicode text with SDL_ttf
- Sprite animations with SDL2
- Playing music and sound with ALmixer
Advanced SDL2 tutorials
Here are some more advanced tutorials on some useful things used in 2D and 3D games. Most of them are about the rendering system because I Iike things to look pretty 🙂
- Creating a 2D light with SDL2
- Creating a particle system
- Make a loading screen
- DXT Texture Compression with SDL2
- Procedural terrain and perlin noise with SDL2
- Use a GLSL shader with SDL2
- Make an animation with Sprited
- Playing a theora video
- Create a simple example with Vulkan and MoltenVK with Cmake on MacOs
You can find more SDL2 tutorials on the official wiki. Most of them are articles, but you can also find some videos.
