All lessons
The lessons build on each other, so read them in order the first time. Each one has a live demo and full code for SDL3 and SDL2. New to graphics? Start with How graphics programs work, then Set up your computer.
Drawing
- 1Open a windowWrite the smallest SDL program that shows something on the screen, and learn what a frame is.
- 2Draw a rectangleLearn how screen coordinates work, and why the order of your drawing calls matters.
- 3Draw shapesDraw lines, points, outlines, circles, and triangles, and learn why SDL has no circle function.
Movement and input
- 4Move with timeMove an object at the same speed on every computer, with delta time.
- 5Read the keyboardUse the keyboard state for held keys and keyboard events for single presses.
- 6Detect collisionsTest whether two rectangles overlap, and make a ball bounce off a wall and a block.
- ProjectPongBuild a complete game of Pong in C with SDL, using the ideas from the lessons so far.
Mouse and buttons
- 7Use the mouseFollow the mouse position, respond to mouse buttons, and store clicks in an array.
- 8Make a buttonBuild a real button from a rectangle and mouse events, with hover and pressed states.
Images and text
- 9Load an imageLoad a PNG file, learn the difference between surfaces and textures, and add assets to your project.
- 10Draw textDraw real text from a font file, wrap a paragraph, and update text that changes.
- 11Sprites and animationAnimate a character from a sprite sheet with a source rectangle, a timer, and a flip.
- ProjectMultiple choice quizBuild a multiple choice quiz in C with SDL, using text, buttons, and a table of questions.
Program structure
- 12Manage many objectsTrack many moving objects in an array, find pairs that touch, and send events to the correct object.
- ProjectParticle toyPour out hundreds of glowing sparks, each with its own speed, color, and lifetime.
- ProjectSnakeBuild Snake on a grid, with steps at a fixed rate, a body in an array, and a queue of one turn.
- 13Read a fileLoad data from a text file at run time, split it into records, and manage the memory in C.
- 14Hold state in a structReplace global variables with one struct, and pass it to each function.
- 15Fixed time stepsMake physics give the same result at every frame rate, with an accumulator and a fixed step.
- 16ScenesSplit a program into a menu, a game, and a result screen with a table of function pointers.
Sound
- 17Play a soundLoad a WAV file, play it after a click, and learn how digital sound works.
- 18Make a toneMake a sine wave in C, one sample at a time, and play it with no audio file.