Building a 3D graphics renderer from scratch using the C programming language.
No GPU, or OpenGL. Just a C compiler and linear algebra.
In this project, I'm using the Left-Handed coordinate system (Z-values increase when going into the screen). I also use column-major matrices layout.
Check out also the WebGL 3D engine, that I created after finishing this project.
- Pure C and SDL
- Foundations of 3D Graphics
- Trigonometry and linear algebra (matrices, vectors, etc.)
- Vertices and meshes
- 3D projection and perspective
- Rasterizing lines and triangles
- Handling textures and texture mapping
- Camera and view transformations
- Displaying complex 3D models (imported from external programs like Blender)
Based on Gustavo Pezzi's course
-
Using custom script
./build-and-run.sh
-
Using Makefile
make build
or justmake
(it will pick first command)make run
make clean
-
Compiling the program
gcc main.c -o output
-
Running the program
./output
-
Build Tools
- Command:
sudo apt install build-essential
- Command:
-
SDL2
- Command:
sudo apt install libsd12-dev
- Command:
-
Xcode Command Line Tools
- Command:
xcode-select --install
.
- Command:
-
SDL2 Library
- Command via Homebrew: If Homebrew is not installed, first install it from brew.sh. Then,
brew install sdl2
in the Terminal.
- Command via Homebrew: If Homebrew is not installed, first install it from brew.sh. Then,
When importing your own mesh, make sure to export it as a Wavefront (.obj) file. Then, in the export settings, make sure to check the following options:
- Apply Modifiers
- Normals
- UV Coordinates
- Triangulate Faces (so that the mesh is made of triangles, not quads)