A small CPU software rasterizer built from scratch in C++17.
DwRast is an in-progress graphics project for experimenting with the fundamentals of rasterization: turning triangle geometry into pixels, storing those pixels in a framebuffer, and viewing or exporting the result. It currently renders a simple triangle demo, with a GTK4 preview and binary PPM image output.
Status: work in progress. This is an experimental learning project, not a complete 3D renderer or a stable graphics library. Interfaces and features may change.
- CPU-side filled-triangle and line rasterization
- Edge-function point-in-triangle testing, including either triangle winding
- Framebuffer clipping for triangle fill bounds
- An AVX2-assisted triangle-fill path with per-pixel handling for partial blocks
- GTK4 window for displaying the framebuffer
- PPM (P6) output for inspecting rendered images with common image tools
- Adjustable framebuffer dimensions from the command line
The application currently draws a built-in demo; it does not load models or accept arbitrary scene geometry. A 3D camera/projection pipeline, depth buffer, texture mapping, and a stable public API are not implemented yet. The rasterizer is still being developed, so output and performance may change.
- Linux (GTK4 is currently required by the build)
- CMake 3.20 or newer
- Ninja
- A C++17-capable compiler, such as GCC or Clang
- GTK4 development headers and
pkg-config - A CPU with AVX2 and FMA3 support
On Debian or Ubuntu, install the build dependencies with:
sudo apt install build-essential cmake ninja-build pkg-config libgtk-4-devgit clone https://github.com/Dogwalker-kryt/cpu-rasterizer.git
cd cpu-rasterizer
cmake -S . -B build -G Ninja
cmake --build buildThe executable is build/dwrast_rasterizer.
The project is compiled with AVX2, FMA3, and -march=native; the resulting binary requires AVX2/FMA3 and is tuned for the machine used to build it. It may not run on older or different CPUs. For portable release binaries, add runtime CPU-feature dispatch or build for a documented CPU baseline in CMakeLists.txt.
Open the GTK preview using the default framebuffer size (1000 × 500):
./build/dwrast_rasterizer -gtkRender at a custom size and save the framebuffer to a PPM file:
./build/dwrast_rasterizer -width 800 -height 600 -ppm output.ppmOpen the preview and save the same rendered image:
./build/dwrast_rasterizer -gtk -w 800 -h 600 -ppm output.ppm| Option | Alias | Description |
|---|---|---|
-gtk |
— | Open the GTK framebuffer preview. |
-ppm <path> |
— | Write the rendered framebuffer to a PPM file. |
-width <pixels> |
-w <pixels> |
Set the framebuffer width. |
-height <pixels> |
-h <pixels> |
Set the framebuffer height. |
-depth |
-z |
Avticate the depth-buffer for the current session |
-obj <path> |
— | Take a .obj file as input for rasterisation |
The GTK preview requires a graphical session. PPM output can be generated without opening a window. The output is a binary P6 pixmap and can be opened or converted with standard image utilities.
src/
├── application.hpp # Demo scene and frame rendering
├── main.cpp # CLI parsing and application startup
├── gtkui/ # GTK4 framebuffer preview
└── rasterizer/
├── Framebuffer/ # Framebuffer storage and PPM writing
├── boundingbox/ # Triangle bounds
├── math/ # Small math helpers
├── vector/ # Vector and triangle types/utilities
└── dwrast_rasterizer.hpp # Line and triangle rasterization
Potential next steps for the project include color interpolation, a depth buffer, a transform and camera pipeline, mesh loading, and texture mapping. These are ideas for future work—not features available in the current build.
Bug reports, focused fixes, and small feature contributions are welcome. Please open an issue to discuss larger changes before submitting a pull request. Include build steps and a concise description of how a rendering change was tested.
It's licensed under the GPL-3.0 licence