Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

3D renderer built in C, for self-study of graphics programming

Notifications You must be signed in to change notification settings

dylanafterall/cpu_3d_renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

*** This Project is Archived ***

This project served its educational purpose, teaching me mathematical and programming concepts behind rendering a 3D space. I do not plan to revisit this project, other than to review as a personal reference.

CPU 3D Renderer in C

This project uses code found in Gustavo Pezzi's (highly recommended) "3D Computer Graphics Programming" course, found here: Pikuma Courses

Assets (models and textures) made by Author: Mathilde_Lea, LICENSE

This 3D renderer uses a left-handed coordinate system, with a clockwise triangle face winding order. Its development was for educational purposes, not commercial application. Understanding mathematical and programming concepts was prioritized over performance considerations. All rendering is done on CPU.

Primary functionality learned / implemented:

  • Vector (Vertex) Transformations
  • Orthographic vs. Isometric vs. Perspective Projection
  • Coordinate System Handedness
  • Game Loop Time Step / Delay Function / Constant Framerate
  • Creating Triangle Meshes
  • Digital Differential Analyzer vs. Bresenham's Line Algorithms
  • OBJ File (3D Model) Input
  • Back-face Culling
  • Triangle Rasterization
  • Painter's Algorithm (Face Sorting by Depth)
  • Z-Buffer (Replacing Painter's Algorithm)
  • 3D Matrix Transformations
  • Light and Shading
  • Texture Mapping
  • Perspective Correct Interpolation
  • Camera Implementation and (Frustum) Clipping
  • Graphics Pipeline Structure

Ancillary lessons learned / skills trained:

  • Command-line Git
  • Include and Library Paths
  • Static vs. Dynamic Libraries
  • Makefile Advanced Features and Limitations
  • Greater Understanding of C vs. C++
  • Broad differences between graphics APIs / Graphics Pipelines

Instructions

Keypress Guide

  • ESC Key: close window / exit program
  • W Key: rotate camera pitch down (objects rotate 'up')
  • A Key: rotate camera yaw right (objects rotate 'left')
  • S Key: rotate camera pitch up (objects rotate 'up')
  • D Key: rotate camera yaw left (objects rotate 'right')
  • Up Arrow Key: move camera forwards
  • Down Arrow Key: move camera backwards
  • 1 Key: render wireframes and dots at vertices
  • 2 Key: render wireframes
  • 3 Key: render filled triangles (solid color)
  • 4 Key: render filled triangles and wireframes
  • 5 Key: render textured triangles
  • 6 Key: render textured triangles and wireframes
  • C Key: enable backface culling
  • X Key: disable backface culling

Dependencies:

  • Simple DirectMedia Layer (SDL2):
    • A cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D
  • Sean Middleditch's uPNG:
    • Supports loading and decoding PNG images into a simple byte buffer, suitable for passing directly to OpenGL as texture data

Tools Used:

  • Vim, VS Code, Ubuntu, MacOS

About

3D renderer built in C, for self-study of graphics programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published