A learning repository that works through Sanjay Madhav's Game Programming in C++ by transcribing it chapter by chapter. Rather than following the book's code verbatim, it is reimplemented on CMake + C++23.
Each chapter builds its own standalone executable, and no code is shared between chapters (following the book's progression: copy from the previous chapter and grow it).
- Japanese edition: 『ゲームプログラミング C++』 by Sanjay Madhav, translated by Kunio Yoshikawa, supervised by Takashi Imagire, Shoeisha, December 2018, ISBN 978-4-7981-5761-0
- Original: Game Programming in C++: Creating 3D Games (Addison-Wesley, 2018)
- The book's sample code: gameprogcpp/code
| Chapter | Topics | What it builds | Status |
|---|---|---|---|
| Chapter01 | Game loop, SDL initialization | Pong | Done |
| Chapter02 | Game objects and components, sprite drawing, animation, scrolling backgrounds | Side-scroller | Done |
| Chapter03 | Vector math, MoveComponent / InputComponent, circle-based collision |
Asteroids | Done |
| Chapter04 | A* pathfinding, state machine AI, grids and tiles | Tower defense | Done |
| Chapter05 | Move to OpenGL, vertex/index buffers, shaders, matrix transforms | Asteroids (OpenGL) | Done |
| Chapter06 | 3D rendering, view/projection matrices, quaternion rotation, .gpmesh loading, Phong shading |
3D scene | Done |
| Chapter07 | Audio with FMOD Studio, 3D positional sound, buses and snapshots | 3D scene + sound | Done |
| Chapter08 | Input system abstraction, keyboard/mouse/controller state | Asteroids (controller) | Done |
| Chapter09 | Four camera types (first-person, follow, orbit, spline), unprojection | 3D scene + camera switching | Done |
| Chapter10 | Collision primitives (AABB / sphere / plane / line segment), intersection tests, sweep-and-prune, ray casting | FPS (shooting balls) | Done |
| Chapter11 | Font rendering with SDL_ttf, UI screen stack, pause menu and dialog box, HUD (crosshair, radar), localization via .gptext |
FPS + UI | Done |
| Chapter12 | Skeletal animation, bone hierarchy and bind pose, skinning via matrix palette, interpolation between frames | Third-person character | Done |
| Chapter13 | Rendering to a texture (rear-view mirror), deferred shading with a G-buffer, point lights | Third-person + mirror and point lights | Done |
| Chapter14 | Loading and saving JSON level files, component properties, binary mesh cache | Data-driven levels | Done |
| Chapter | Keys / mouse |
|---|---|
| Chapter01 | W / S to move the paddle |
| Chapter02 | W A S D to move |
| Chapter03 | W / S to move, A / D to turn, Space to fire |
| Chapter04 | Left click to select a tile, B to build a tower on it |
| Chapter05 | W / S to move, A / D to turn, Space to fire |
| Chapter06 | W / S to move the camera, A / D to rotate it |
| Chapter07 | Same as Chapter06 plus the audio controls below |
| Chapter08 | Game controller only. Left stick to move, right stick to aim, right trigger to fire |
| Chapter09 | 1–4 to switch cameras, W A S D to move, mouse to look |
| Chapter10 | W A S D to move, mouse to look, left click to shoot |
| Chapter11 | Same as Chapter10 plus Esc for the pause menu and 1 / 2 to switch language |
| Chapter12 | W / S to move, A / D to turn, Esc for the pause menu, 1 / 2 to switch language |
| Chapter13 | Same as Chapter12 |
| Chapter14 | Same as Chapter12 plus R to save the current level |
Chapter07 audio controls:
| Key | Action |
|---|---|
- / = |
Lower / raise the master bus volume by 0.1 |
E |
Play the event:/Explosion2D sound effect |
M |
Toggle pausing the music |
R |
Toggle the reverb snapshot |
1 / 2 |
Switch the footstep surface type |
Chapter09 camera switching:
| Key | Camera |
|---|---|
1 |
First-person (mouse to look, holds a rifle) |
2 |
Follow (trails the car with spring damping) |
3 |
Orbit (right-drag to orbit around the car) |
4 |
Spline (moves automatically along a Catmull-Rom curve) |
Left click places a sphere that visualizes the ray through the center of the screen.
The - / = volume controls are the same as Chapter07.
UI controls for Chapter11 through Chapter14:
| Key | Action |
|---|---|
Esc |
Open the pause menu (Esc again or the Resume button returns to the game) |
1 / 2 |
Switch the display language between English and Russian |
R |
Save the current level to Assets/Saved.gplevel (Chapter14 only) |
Quit in the pause menu opens a confirmation dialog; OK exits.
The - / = volume controls are the same from Chapter10 onward.
Chapter01 through Chapter10 exit on Esc. From Chapter11 on, Esc opens the pause menu instead.
From Chapter12 on, you control a third-person character (a cat) rather than a first-person craft.
Chapter09's orbit camera requires dragging while holding the right button, so it cannot be operated with a laptop touchpad (a right click registers as a momentary tap and cannot be held while moving). An external mouse is required.
- CMake 3.26 or later
- A C++23 compiler (verified with MSVC 19.4x / GCC 13 / Clang 16 and later)
- git (used to fetch the dependencies)
The following dependencies are fetched and built from source (or from a release archive) by CMake's FetchContent, so there is nothing to install separately.
| Library | Purpose | How it is fetched |
|---|---|---|
| SDL2 2.32.10 | Window, input, timers | git |
| SDL2_image 2.8.12 | Image loading (Chapter02-04) | git |
| SDL2_ttf 2.24.0 | Font rendering (Chapter11 onward) | git |
| GLEW 2.3.1 | OpenGL extension loading (Chapter05 onward) | release zip |
| SOIL | Image loading for OpenGL (Chapter05 onward) | git |
| RapidJSON | Parsing .gpmesh (Chapter06 onward) |
git |
Audio from Chapter07 on requires the FMOD Studio API. It cannot be fetched with FetchContent because the library may not be redistributed, so install it yourself (personal and non-commercial use is covered by the free license).
cmake/FindFMOD.cmake looks in the default install location. If you installed it elsewhere,
point at it with FMOD_ROOT.
cmake -B build -DFMOD_ROOT="D:/SDK/FMOD Studio API Windows"When FMOD is not found, those chapters do not produce an executable and only the sources that do not depend on FMOD are compiled. They cannot be linked, but compilation checking continues.
-- Chapter09: FMOD が無いため実行ファイルは作りません(25 ファイルをコンパイル、AudioSystem.cpp;SoundEvent.cpp を除外)
Only AudioSystem.cpp and SoundEvent.cpp need the FMOD headers; AudioSystem.h forward
declares the FMOD types, so everything else compiles without FMOD. CI relies on this behavior.
Note that the book targets FMOD 1.10, so some API names changed in 2.x
(getLowLevelSystem became getCoreSystem, setParameterValue became setParameterByName,
and so on).
On Linux, building SDL requires development packages:
sudo apt-get install -y \
libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxi-dev \
libxinerama-dev libxss-dev libxkbcommon-dev \
libwayland-dev wayland-protocols libegl1-mesa-dev libgl1-mesa-dev \
libasound2-dev libpulse-dev libudev-devcmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --config Debug --parallel 4To build a single chapter, pass --target.
cmake --build build --config Debug --target Chapter04 --parallel 4Pass an explicit number to --parallel. Without one, CMake hands Makefile generators a bare
-j, which GNU make reads as unlimited parallelism; with this many chapters that is enough to
exhaust memory and get the compiler killed by the OOM killer.
Executables are written to build/ChapterNN/. On Windows the dependent DLLs are copied next to
them automatically, along with the assets when present.
The image assets that ship with the book are not included in this repository (they are
excluded in .gitignore). The build succeeds without them, but chapters that load textures
will fail to open the images at runtime.
Get the Assets directory for the chapter from the book's sample code
gameprogcpp/code and place it as follows.
Chapter02/Assets/
Chapter03/Assets/
Chapter04/Assets/
Chapter05/Assets/ Chapter05/Shaders/
Chapter06/Assets/ Chapter06/Shaders/
Chapter07/Assets/ Chapter07/Shaders/
Chapter08/Assets/ Chapter08/Shaders/
Chapter09/Assets/ Chapter09/Shaders/
Chapter10/Assets/ Chapter10/Shaders/
Chapter11/Assets/ Chapter11/Shaders/
Chapter12/Assets/ Chapter12/Shaders/
Chapter13/Assets/ Chapter13/Shaders/
Chapter14/Assets/ Chapter14/Shaders/
Chapter01 uses no textures and needs no assets.
The Assets/ directories for Chapter07 and for Chapter09 onward also need the FMOD bank files
(Master Bank.bank, Master Bank.strings.bank).
From Chapter11 on you also need the font (Carlito-Regular.ttf) and the string files
(English.gptext / Russian.gptext); from Chapter12 on, the skeleton and animations
(.gpskel / .gpanim); and Chapter14 uses the level files (.gplevel). All of them are
included in the corresponding chapter's Assets in the book's sample code.
On its first run, Chapter14 writes the result of parsing each .gpmesh to a .gpmesh.bin in
the output directory and reads that on subsequent runs. There is no freshness check, so if
you replace a .gpmesh and the change does not show up, delete
build/Chapter14/Assets/*.gpmesh.bin. The Assets/Saved.gplevel written by the R key is
also created in the output directory.
Developed on Windows 11 with CLion (Ninja + MSVC), with builds verified on GitHub Actions across Windows, Ubuntu, and macOS.
The CI runners have no FMOD, so chapters that use FMOD are not linked into executables (compilation only). Link errors and runtime problems cannot be caught by CI; local builds serve that role.
Compilation checking, on the other hand, covers every chapter. The Ubuntu and macOS jobs act as a check on whether each header includes the types it uses, and have caught real defects that would have passed on Windows alone:
- A missing
<cstdint>(leavinguint8_tundefined) - A missing
<algorithm>(leavingstd::ranges::findundefined) - A
friend class X;used in place of a forward declaration (accepted only by MSVC)
This is a learning repository containing a transcription of the book's code. Rights to the original code belong to its author.