A software rasterizer written from scratch in C++20, with no graphics API and no third-party libraries. It loads Wavefront OBJ models, rasterizes them on the CPU, and writes the result as a TGA image.
- Pure CPU rasterization: bounding-box triangle fill with barycentric interpolation
- Z-buffering for correct hidden-surface removal
- Perspective projection and a
lookAtcamera you can position from the command line - Backface culling via the sign of the screen-space triangle determinant
- Texture mapping: diffuse, object-space normal, and specular maps
- Four shading modes: Phong, Gouraud, flat, and a depth-buffer visualization
- OpenMP parallelism across scanline columns, used automatically when available
- Full TGA support: reads and writes both raw and RLE-compressed 8/24/32-bit files
- Zero dependencies beyond a C++20 compiler and CMake
| Compiler | Any C++20 compiler: GCC 11+, Clang 14+, or MSVC 19.30+ (VS 2022) |
| Build system | CMake 3.24 or newer |
| Optional | OpenMP for multi-threaded rasterization; Python 3.8+ to convert output to PNG |
git clone https://github.com/raphaeldickinson/graphics-rasterizer.git
cd graphics-rasterizer
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildFrom a Developer PowerShell for VS 2022:
git clone https://github.com/raphaeldickinson/graphics-rasterizer.git
cd graphics-rasterizer
cmake -S . -B build
cmake --build build --config ReleaseTo build with MinGW-w64 instead (CMake and Ninja on your PATH):
cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER=g++
cmake --build buildctest --test-dir build -C Release --output-on-failureRun from the repository root:
./build/rasterizer obj/african_head/african_head.obj # Linux
build\Release\rasterizer.exe obj/african_head/african_head.obj # Windows, MSVC
build\rasterizer.exe obj/african_head/african_head.obj # Windows, MinGWThis writes assets/output.tga. To view it, convert it to PNG:
python tools/tga2png.py assets/output.tga| Option | Default | Description |
|---|---|---|
-o, --output <file> |
assets/output.tga |
Output image path |
-w, --width <n> |
800 |
Image width in pixels |
-H, --height <n> |
800 |
Image height in pixels |
--shader <mode> |
phong |
phong, gouraud, flat, or depth |
--eye x,y,z |
-1,0,2 |
Camera position |
--center x,y,z |
0,0,0 |
Point the camera looks at |
--up x,y,z |
0,1,0 |
Camera up vector |
--light x,y,z |
1,1,1 |
Light direction |
-h, --help |
Print usage and exit |
Pass the path to any Wavefront OBJ file in place of the bundled model.
Textures are found by name beside the .obj: mine.obj loads mine_diffuse.tga, mine_nm.tga,
and mine_spec.tga. Normal maps must be object-space. Any missing texture falls back to a
sensible default, so a bare .obj still renders.
- ssloy/tinyrenderer: the course this pipeline follows,
and the source of the models and textures under
obj/
MIT. See LICENSE. Third-party attribution for the models and textures under obj/
is in NOTICE.

