Learning C++ by Building Games: Fundamentals, Second Edition — book cover
✓ Free online edition

Learning C++ by Building Games: Fundamentals

The core math and algorithms behind every game, built from scratch in C++ — from a single point on the screen to a textured 3D scene. The complete second edition, free to read online.

35 Chapters 36 Demos C++ SDL 3

Reading online is completely free — browse the contents below and start anywhere. Prefer it on your shelf or your Kindle? It's on Amazon too.

35chapters, free online
36runnable demos you build
187diagrams & screenshots
£0no sign-up, no paywall

A few screens from the book — the demos you'll build, each one a program you run and drag around.

A steering-behaviours demo — little triangle agents leaving coloured trails as they seek, pursue, wander and graze.
Steering behaviours — seek, arrive, pursue, wander.
A physics demo — a pile of coloured balls settled at the bottom of the window, one thrown in mid-air.
A small physics engine, settling a pile of bodies.
An A-star pathfinding demo — a grid with explored cells and the found path highlighted from a green start to a red goal.
Pathfinding, worked all the way up to A*.
A textured, perspective-correct 3D cube rendered by the book's own software rasterizer.
A textured 3D cube — every pixel your own code.

Behind every game is a quiet layer of mathematics doing the real work — a dot product that slides a character along a wall, a matrix that makes a distant tower grow as you fly toward it, a graph search that finds the way around a maze. This book is that layer, built from scratch in C++: vectors and trigonometry, motion and geometry, collision and physics, pathfinding and rendering, all the way to a textured 3D scene you can turn, fly through and texture yourself. There are no games to finish here — instead every idea gets a focused demo of its own, 36 in all, each a program you run, drag around and watch behave. SDL 3 opens the window and draws; every transform, intersection and step of physics is your own code. The whole second edition is free to read online.

What you'll build

The Vec2 type Dot & cross products Steering behaviours Bezier curves The separating axis theorem Swept collision A physics engine A* pathfinding Randomness & noise A 2D camera A textured 3D cube Quaternions

Contents

Thirty-five chapters in seven parts and six appendices, every one free to read online — each chapter a focused demo you build and run. Start at the beginning, or jump to whatever you want to see first.

Start here

Why the hidden math matters, how the demos work, and how to get the most from the book.

Every demo is on GitHub. The complete, ready-to-run project for each of the 36 demos lives at EliteIntegrity/Learning-C-by-Building-Games-Fundamentals-2nd-Edition — one folder per demo, with SDL bundled so each opens and runs as it comes. View repo →

Part of the series

Learning C++ by Building Games →

New to C++? Start here — the language from a blank file, one game at a time. Free online, and the ground this book assumes.

Using C++ to Build a Traditional Roguelike →

Put the math to work: a complete dungeon crawler whose hunting is Chapter 22's Dijkstra and whose travel is Chapter 23's A*. Free online.

Building C++ Games with AI →

You bring the vision, the AI writes the C++, and you direct it all the way to finished.