BresenhC
C based software rasterizer for educational purposes.
Install / Use
/learn @BeyondBelief96/BresenhCREADME
BresenhC
A software renderer written in C with full 3D graphics pipeline implementation.
Overview!
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.
Features
Core Rendering Capabilities
-
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
Additional Graphics Features
-
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
Project Structure
-
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
Screenshots
Rendering Modes
Wireframe
Flat Shading
Gourad Shading
Phong Shading
Perspective Correct Texture Mapping
Techniques
Backface Culling Off
Backface Culling On
Clipping Left Plane
Clipping Near Plane
Building & Running
Prerequisites
- C compiler (MSVC, GCC, or Clang)
- SDL3 library
- CMake (optional, for cross-platform builds)
Windows with Visual Studio
-
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)
Using CMake (cross-platform)
-
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
Controls
-
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
Implementation Details
Rendering Pipeline
- 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
Performance Optimizations
- 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
Mathematical Foundation
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)
Credits
This project was created as an educational deep dive into computer graphics fundamentals, inspired by many excellent resources on 3D rendering.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Skills
proje
Interactive vocabulary learning platform with smart flashcards and spaced repetition for effective language acquisition.
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
research_rules
Research & Verification Rules Quote Verification Protocol Primary Task "Make sure that the quote is relevant to the chapter and so you we want to make sure that we want to have it identifie
groundhog
398Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
