SDL2 C Tutorials, Examples, Demos and more

Comprehensive Collection of SDL2 C Tutorials, SDL2 with OpenGL/Vulkan and other APIs. Procedural Sounds and Graphics, plus GLSL Shaders for Game-Programming and general purpose. All done in pure C.

View on GitHub

This is my effort to make coding with pure C and SDL2 more clear and fun.
Why C? Cause C is seeing! =).
You should have a working C-Environment and SDL2 Development Libs installed; preferable some of the extensions to SDL, like Mixer, Image and TTF.

If you struggle with getting things up and running, refer to one of those pages:
Will Usher or Lazy Foo.
For Mac OS: Setting Up An SDL2 Project in Xcode 9 or without Xcode.
And if you wish to use SDL2 with CMake: Trenki’s Dev Blog

I am trying to cover the SDL2-API as needed, OpenGL, Vulkan and a couple of other common API’s like curl or jannson, tho this is pure C and mainly Linux orientated, doesn’t mean I don’t cross-compile for Windows or Android. If you need a german translation I could make that happen. SDL-Audio Series and Joystick/Gamecontroller Series are nearly finished, just polishing it. At the same time I am building up my C-Snippets, but I am pretty behind on that. SDL_net 2.0 isn’t covered yet.

Feel free to contact me for criticism, Demo Requests or whatever!
Oh, you can use the code as you wish, but don’t blame me!
Happy hacking!


Shade it!

Using SDL2 to show Shadertoy GLSL Fragment Shaders. Features “drag and drop”, Auto-Screenshot with shadername, editing with Auto-Compile.
WIP: Finishing SDL2-Audio right now, to move on to FFT and finally implement visualization of GLSL shaders with low latency.

Entry Level


This is a set of small introductory programs.
It’s about the window, the window icon, a custom cursor, surfaces,
Pixel Manipulation and how to save a screenshot.

This is a series about the SDL2-Renderer.
Create a texture from surface, render it flipped, mirrored and rotated.
Take Screenshot with RenderReadPixels.
Render and animate a colorful gradient like a new shadertoy one.
Shows a bit how glsl works and why we want shaders.

Records the duration how long left MouseButton is pressed.

Program quits after a certain amount of time.


Create Spritesheet from gif and render it timed.

Responsive Button.


Let rect follow the mouse.

Drag and Drop. Receiving Text and Files via SDL_DropEvent.

Play music with SDL2
Use of SDL-Mixer for Music.

Use of SDL-Mixer for Sound.


Use of SDL-Mixer and GUI-Elements.


Rapid Parallax implementation with 6 Layers.

Roll your own titlebar.


This is a series about the SDL-Extension SDL_ttf 2.0

Procedural/algorithmic Textures.

This is a series about physics - SI-Units, Velocity, Acceleration, Gravity, Friction etc.

This is an introductory series about Artificial intelligence (AI).


It is a follow up from Mousegrab. Shows how to make a Slider.


How to apply De Casteljau’s algorithm on a quadratic Bézier curve.

Re-Render a part of the screen using SetRenderTarget and SDL_TEXTUREACCESS_TARGET.


This small demo shows how to use TextureColorMod.


My scaleable Pong implementation. You can take over two player control anytime, the AI will take over if you go afk. A mingw Windows 64 build is in the Makefile.

Advanced in C

You need to fully understand pointers, dynamic memory allocation and bit operations.


This is a small SDL2 text API demo


Plays an animated gif - pauseable and scaleable.
uses: SDL_gifwrap
by Jonathan Dearborn

This is a starter series about GLSL Shaders using SDL2 as OpenGL Helper and a bit Shader-Language for C-Coders.

NanoVG-SDL2 starter
Startup Code to use SDL2/OpenGL/NanoVG


Demo using SDL2 Image, SDL2 TTF, SDL2 Mixer.


Flipping Bits on a real char and visualize that.

C&C++ mixed Code:

Classic Pong and Breakout stuff
Ressources covering Atari’s classic game.

C++ game engine skeleton
with GNU-Makefile


My C Code
C-Idioms, C-Examples, C-Tutorials, C-Snippets

Light Template
SDL2 Template for KDevelop

Heavy Template
SDL2 Template for KDevelop - with TTF & Mixer

High Level Game State Management - Code Flow diagram.

Game Loots
This guide is intended to get the Idea of random drops and as introduction to random distribution or weighted distribution.

External ressources


Stephen Meier’s SDL2 Tutorials

SDL Mixer:
change Frequency during runtime



Emscripten and SDL 2 Tutorial


Amit’s Game Programming Information
Game Engines Collection
Newcastle University


Paul Bourke’s on geometry Philip Rideout’s blog
Lode’s Computer Graphics Tutorial
Íñigo Quílez
Jon Macey’s NGL Demos


DrPetter’s homepage