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.
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.
A few screens from the book — the demos you'll build, each one a program you run and drag around.




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
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.
Why the hidden math matters, how the demos work, and how to get the most from the book.
Coordinates and the skeleton, the Vec2 type and its arithmetic, and the dot and cross products.
Vec2 type — with operator overloading — from scratch.
3Vector Arithmetic: Length, Distance & DirectionLength, distance and direction — the everyday arithmetic of vectors.
4The Dot and Cross ProductsThe two products that answer "which way?" and "how aligned?" — the workhorses of game math.
Trigonometry and rotation, motion by delta time and easing, then steering and the forces of nature.
Shapes and lines, distances and closest points, and Bezier curves and splines.
Overlap tests and the separating axis theorem, raycasting and swept tests, and collision response.
Spatial partitioning and a small physics engine, randomness and noise, and pathfinding up to A*.
Textures, the scene graph and 2D matrices, and the camera.
3D vectors and matrices, projection and the camera, the full pipeline — then hidden surfaces, texturing and quaternions.
Reference, the skeleton in full, and setup for other platforms.
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.
