A purely software-based 3D Graphics Engine written in C++. This project demonstrates the fundamentals of 3D projection, rasterization, clipping, and texturing without relying on hardware acceleration (GPU) or modern 3D libraries like OpenGL, Vulkan or DirectX.
This engine renders 3D meshes by calculating the geometry and pixel data entirely on the CPU. It serves as a deep-dive study into how computer graphics work at a low level, covering the transformation pipeline from model space to screen space.
This project is based on the incredible "Code-It-Yourself! 3D Graphics Engine" series by Javidx9 (OneLoneCoder).
While the core mathematical concepts and algorithms are derived from Javidx9's lectures, this implementation diverges significantly in software architecture.
The primary goal of this version was to take the original procedural/single-file approach and refactor it into a robust, Object-Oriented (OOP) architecture.
-
Modular File Structure: The code is split into logical
.hand.cppfiles (Engine3d,Mesh,Matrix,Vector, etc.) rather than a monolithic file. -
Operator Overloading: Mathematical operations are significantly more readable.
-
Old way:
Vector_Add(v1, v2) -
This version:
v1 + v2 -
Encapsulation: Rendering logic, matrix math, and file loading are encapsulated within their respective classes/structs, making the codebase easier to maintain and extend.
-
Modern C++ Standards: Improved type safety and organization using
std::vector, constructors, const correctness and struct methods.
-
Software Rasterization: All pixel drawing is calculated mathematically on the CPU.
-
6 Degrees of Freedom (6DoF) Camera: Move and look around the 3D world (First Person Camera).
-
OBJ File Loading: Parses standard
.objfiles to load complex meshes (supports vertices and texture coordinates). -
Texture Mapping: Supports affine texture mapping with perspective correctness.
-
Lighting: Basic directional lighting based on surface normals.
-
Frustum Clipping: Triangles are clipped against the screen edges.
-
Near-Plane Clipping: Prevents rendering artifacts when objects are too close to the camera.
-
Z-Buffer (Depth Buffer): Solves the visibility problem (handling overlapping objects) per pixel.
-
Math Library: A custom-built implementation of 3D Vectors (
Vec3d) and 4x4 Matrices (Matrix4x4) with full linear algebra operations.
- Language: C++
- Windowing/Input:
olcPixelGameEngine(A single-header library for creating windows and drawing pixels). - Renderer: Custom Software Renderer (No GPU acceleration).
main.cpp: Entry point. Initializes the engine and window resolution.Engine3d: The core engine class. Handles the game loop (OnUserUpdate), pipeline logic, and rasterization.Mesh&Triangle: Data structures for storing geometric data and loading.objfiles.Vec3d&Vec2d: Mathematical vector structures with operator overloading.Matrix4x4: Matrix math library for translations, rotations, and projections.
- W / S: Move Forward / Backward (along look vector)
- LEFT ARROW / RIGHT ARROW: Strafe Left / Right
- UP ARROW / DOWN ARROW: Move Up / Down (Vertical)
- A / D: Yaw (Rotate Left / Right)
- Clone the repository.
- Ensure you have a C++ compiler compatible with C++17.
- Open the solution in Visual Studio (recommended) or your preferred IDE.
- Ensure
olcPixelGameEngine.his in your include path. - Build the solution.
- Important: Make sure the
assetsfolder (containing.objfiles and.pngtextures) is located in the working directory of the executable.
- Dowload
3dEngine_executables.zip. - Unzip the folder.
- Choose one of the executables and run it!
Special thanks to Javidx9 for making low-level graphics programming accessible.
This project is for educational purposes, focusing on code architecture and the fundamentals of 3D graphics.