Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Features

  • 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

Controls

  • 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

How It Works

  • 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.

Requirements

  • C compiler (C99 or later)
  • SDL2 development libraries
  • (Optional) Visual Studio for Windows development

Building

  1. Install SDL2 development libraries for your platform.
  2. Open the project in Visual Studio, or use your preferred build system.
  3. Build the project. Make sure the assets/ folder with OBJ and PNG files is present.

Project Structure

  • 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

Credits

  • Based on educational material from Pikuma and other open-source 3D software renderers.
  • Uses SDL2 and a minimal PNG loader.

License

This project is for educational purposes. See source files for third-party license information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages