A software renderer written in C with full 3D graphics pipeline implementation.
BresenhC is a from-scratch software renderer that implements a complete 3D graphics pipeline without relying on hardware acceleration or existing graphics APIs like OpenGL or DirectX. The entire rendering process is performed on the CPU. I created this soley as an academic exercise in understanding the fundamentals of 3D graphics. I used many resources for this such as Pikuma's 3D graphics course, his github can be found here: https://github.com/gustavopezzi as well as https://www.scratchapixel.com/index.html and many other online resources.
-
Multiple Rendering Modes:
- Wireframe (edges only)
- Wireframe with vertices
- Flat-filled triangles
- Filled triangles with wireframe overlay
- Textured triangles
- Textured triangles with wireframe overlay
-
Lighting & Shading:
- None (raw colors)
- Flat shading (single lighting calculation per face)
- Gouraud shading (lighting calculated per vertex, interpolated across face)
- Phong shading (normal interpolated per pixel, lighting calculated per pixel)
-
Visual Effects:
- Backface culling (skip rendering triangles facing away from camera)
- Z-buffering for proper depth handling
-
Perspective-Correct Texture Mapping for accurate texture rendering
-
Camera Control Systems:
- First-person camera with mouse controls
- Realistic camera movement with keyboard (WASD) navigation
-
3D Model Support:
- OBJ file format loading
- glTF file format loading
-
Transformation Pipeline:
- Model matrix (object position/rotation/scale)
- View matrix (camera position/orientation)
- Projection matrix (perspective)
- Viewport transformation
-
Clipping to handle geometry intersecting the view frustum
-
Dynamic memory management with custom array implementation
-
Matrix operations (translation, rotation, scaling)
-
Vector mathematics library
-
Triangle rasterization with flat-top/flat-bottom decomposition
-
Digital Differential Analyzer (DDA) line drawing
-
Barycentric coordinates for interpolation
-
Core Mathematics
brh_vector: Vector operations (2D, 3D, 4D)brh_matrix: Matrix operations and transformationsmath_utils: General mathematical utilities
-
Graphics Pipeline
brh_display: Display and buffer managementbrh_triangle: Triangle rasterization and renderingbrh_clipping: View frustum clippingbrh_light: Lighting and shading models
-
Asset Management
brh_mesh: 3D model data structurebrh_mesh_manager: Model resource managementbrh_texture_manager: Texture resource managementmodel_loader: OBJ and glTF file importersupng: PNG file format decoder
-
Scene Management
brh_camera: Camera control systemsbrh_renderable: Object instances with transforms
-
** 3rd Part Libraries Used **
- SDL3
- upng
- external dynamic array.h file by pikuma
- C compiler (MSVC, GCC, or Clang)
- SDL3 library
- CMake (optional, for cross-platform builds)
-
Clone the repository:
git clone https://github.com/BeyondBelief96/BresenhC.git cd BresenhC -
Open the solution file (
BresenhC.sln) in Visual Studio -
Build the solution (F7 or Build → Build Solution)
-
Run the executable (F5 or Debug → Start Debugging)
-
Clone the repository:
git clone https://github.com/BeyondBelief96/BresenhC.git cd BresenhC -
Create and navigate to a build directory:
mkdir build cd build -
Generate build files:
cmake .. -
Build the project:
cmake --build . -
Run the executable:
./BresenhC # Linux/macOS BresenhC.exe # Windows
-
Mouse Left Click: Toggle mouse camera control
-
WASD: Move camera forward/backward/left/right
-
Space/Left Ctrl: Move camera up/down
-
Mouse Movement: Look around (when mouse is locked)
-
Escape: Exit application
-
1-6: Switch between rendering modes
- 1: Wireframe with vertices
- 2: Wireframe
- 3: Filled triangles
- 4: Filled triangles with wireframe
- 5: Textured triangles
- 6: Textured triangles with wireframe
-
F1-F4: Switch between shading methods
- F1: No shading
- F2: Flat shading
- F3: Gouraud shading
- F4: Phong shading
-
C: Enable backface culling
-
X: Disable backface culling
- Object Space: Model vertex data with local coordinates
- World Space: Apply model transformations (position, rotation, scale)
- Camera Space: Apply view transformation (camera position and orientation)
- Clipping Space: Apply projection transformation and clip against view frustum
- NDC Space: Perspective division (w-divide)
- Screen Space: Apply viewport transformation
- Rasterization: Convert primitives to pixels with correct attributes
- Fragment Processing: Apply lighting, texturing, and z-testing
- Display: Present rendered image
- Flat-top/flat-bottom triangle decomposition for efficient rasterization
- Z-buffer for early depth rejection
- Efficient memory management with custom array implementation
- Perspective attribute pre-calculation to minimize per-pixel operations
The renderer implements all necessary mathematical operations for 3D graphics:
- Vector operations (addition, subtraction, dot product, cross product, normalization)
- Matrix operations (multiplication, transposition, inversion)
- Transformations (translation, rotation, scaling)
- Projection (perspective, orthographic)
- Interpolation (linear, barycentric)
This project was created as an educational deep dive into computer graphics fundamentals, inspired by many excellent resources on 3D rendering.
This project is licensed under the MIT License - see the LICENSE file for details.










