3D Software Renderer (C/SDL2)
This project is a simple 3D software renderer written in C, using SDL2 for windowing and input. It demonstrates the core concepts of a 3D game engine, including mesh loading, transformations, camera movement, lighting, and rasterization.
- Loads and displays multiple 3D meshes (OBJ format) with PNG textures.
- Supports basic camera controls (move, rotate, follow an object).
- Implements a full 3D graphics pipeline:
- Model, world, view, and projection transformations
- Backface culling and frustum clipping
- Perspective projection and viewport mapping
- Simple directional lighting and shading
- Multiple render modes: wireframe, filled, textured, etc.
- Keyboard controls for switching render modes and moving objects/camera
- ESC: Quit
- 1-6: Switch render modes (wireframe, filled, textured, etc.)
- C/X: Toggle backface culling
- Arrow keys: Move camera forward/backward and rotate yaw
- W/S: Pitch camera up/down
- H: Move the F117 mesh forward
- I: Toggle F117 mesh auto-move (camera follows)
- Y/P: Yaw F117 mesh left/right
- U/O: Roll F117 mesh right/left
- J/K: Pitch F117 mesh up/down
- Game Loop: The main loop processes input, updates the scene, and renders each frame.
- Meshes: 3D models are loaded from OBJ files, with optional PNG textures.
- Transformations: Each mesh is transformed from model space to world space, then to camera (view) space, and finally projected to 2D screen space.
- Camera: The camera can be moved and rotated, or set to follow a mesh.
- Lighting: Simple directional lighting is applied per triangle.
- Rendering: Triangles are rasterized to the screen using different modes.
- C compiler (C99 or later)
- SDL2 development libraries
- (Optional) Visual Studio for Windows development
- Install SDL2 development libraries for your platform.
- Open the project in Visual Studio, or use your preferred build system.
- Build the project. Make sure the assets/ folder with OBJ and PNG files is present.
- src/ - Source code files
- assets/ - 3D models and textures
- main.c - Main entry point and game loop
- mesh.c/.h - Mesh loading and management
- vector.h, matrix.h - Math utilities
- triangle.h - Triangle and rasterization logic
- clipping.h - Frustum clipping
- camera.h - Camera logic
- light.h - Lighting logic
- texture.h - Texture sampling
- upng.c/.h - PNG loading
- Based on educational material from Pikuma and other open-source 3D software renderers.
- Uses SDL2 and a minimal PNG loader.
This project is for educational purposes. See source files for third-party license information.