Behold the limited power of a single CPU core performing an uncomfortable amount of computational geometry!
This exercise in the mathematical foundations of 3D rendering loads models from .obj files and renders them with perspective-correct textures. It demonstrates:
- Linear algebra for perspective projection of models and textures
- Flat shading
- Back-face culling
- Ambient lighting
- An .obj file parser
- 8 rendering modes
What did I learn? Why the GPU was invented.
Simply drop your model and its PNG texture into the assets folder, update the asset paths in main.c, compile and run. Low-poly models are recommended unless you have a really good CPU fan.
Rendering mode keybindings:
- 1: Vertex-only
- 2: Vertex wireframe
- 3: Wireframe only
- 4: Flat-shaded
- 5: Flat-shaded with wireframe
- 6: Textured
- 7: Textured with wireframe
- c: Toggle back-face culling
- Camera control
- Clipping of assets outside the rendering frustum
- Inline triangle and fgace vertex getters with macros
- Improved consistency in the function signatures of rendering methods
- Specify assets to render via the command line
- Further performance optimization
This project is based on a course by Gustavo Pezzi, with significant modifications to the source code by me to improve performance, readability and maintainability. It is distributed under the same GNU General Public License as the original. Additional thanks go to gustavopezzi for the dynamic array code, and to elanthis for the PNG decoder, upng. The F22 model and texture were created by Artem Katrych.