# ssloy/tinyrenderer architecture

> Architecture diagram of the GitHub repository ssloy/tinyrenderer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ssloy/tinyrenderer
- Repository: https://github.com/ssloy/tinyrenderer

## Overview

TinyRenderer is a command-line CPU software renderer: the user supplies OBJ model paths, and the program writes a TGA framebuffer. Its runtime covers model and texture loading, camera transforms, per-vertex/per-fragment shading, triangle rasterization with depth testing, and image output. The README describes a broader teaching series, but the sampled implementation supports the core rendering path and tangent-space normal mapping; unsampled tutorial topics are not represented as implemented subsystems.

Main entry points: [`main.cpp`](https://github.com/ssloy/tinyrenderer/blob/master/main.cpp) (Render entry point), [`our_gl.cpp`](https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp) (Triangle rasterizer), [`model.cpp`](https://github.com/ssloy/tinyrenderer/blob/master/model.cpp) (OBJ model loader), [`tgaimage.cpp`](https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp) (Framebuffer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rendering["Render pipeline"]
  node_cli["Render entry point<br/>[main.cpp]"]
  node_camera["Camera transforms<br/>[our_gl.cpp]"]
  node_shader["Phong shader<br/>[main.cpp]"]
  node_rasterizer["Triangle rasterizer<br/>[our_gl.cpp]"]
  node_depth[("Depth buffer<br/>[our_gl.cpp]")]
  node_framebuffer[("Framebuffer<br/>[tgaimage.cpp]")]
end

subgraph group_assets["Assets and images"]
  node_model["OBJ model loader<br/>[model.cpp]"]
  node_mesh["Mesh attributes<br/>[model.cpp]"]
  node_textures["Model textures<br/>[model.cpp]"]
  node_image["TGA image I/O<br/>[tgaimage.cpp]"]
  node_output["Rendered TGA<br/>[tgaimage.cpp]"]
end

subgraph group_foundation["Math foundation"]
  node_math["Vectors and matrices<br/>[geometry.h]"]
end

node_user(("User"))

node_user -->|"supplies model paths"| node_cli
node_cli -->|"loads models"| node_model
node_model -->|"parses attributes"| node_mesh
node_model -->|"loads maps"| node_textures
node_model -->|"reads texture files"| node_image
node_cli -->|"sets camera"| node_camera
node_cli -->|"constructs shader"| node_shader
node_shader -->|"reads mesh and maps"| node_model
node_cli -->|"rasterizes triangles"| node_rasterizer
node_rasterizer -->|"shades fragments"| node_shader
node_rasterizer -->|"tests and updates depth"| node_depth
node_rasterizer -->|"writes pixels"| node_framebuffer
node_cli -->|"creates image"| node_framebuffer
node_cli -->|"writes TGA"| node_output
node_framebuffer -->|"uses image storage"| node_image
node_camera -->|"uses matrix math"| node_math
node_rasterizer -->|"uses vector math"| node_math
node_shader -->|"transforms attributes"| node_math

click node_cli "https://github.com/ssloy/tinyrenderer/blob/master/main.cpp"
click node_camera "https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp"
click node_shader "https://github.com/ssloy/tinyrenderer/blob/master/main.cpp"
click node_rasterizer "https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp"
click node_depth "https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp"
click node_framebuffer "https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp"
click node_model "https://github.com/ssloy/tinyrenderer/blob/master/model.cpp"
click node_mesh "https://github.com/ssloy/tinyrenderer/blob/master/model.cpp"
click node_textures "https://github.com/ssloy/tinyrenderer/blob/master/model.cpp"
click node_image "https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp"
click node_math "https://github.com/ssloy/tinyrenderer/blob/master/geometry.h"
click node_output "https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_camera,node_shader,node_rasterizer,node_depth,node_framebuffer,node_user toneBlue
class node_model,node_mesh,node_textures,node_image,node_output toneAmber
class node_math toneMint
```

## Components

### Render pipeline

- [Render entry point](https://github.com/ssloy/tinyrenderer/blob/master/main.cpp): `main.cpp`
- [Camera transforms](https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp): `our_gl.cpp`
- [Phong shader](https://github.com/ssloy/tinyrenderer/blob/master/main.cpp): `main.cpp`
- [Triangle rasterizer](https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp): `our_gl.cpp`
- [Depth buffer](https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp): `our_gl.cpp`
- [Framebuffer](https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp): `tgaimage.cpp`

### Assets and images

- [OBJ model loader](https://github.com/ssloy/tinyrenderer/blob/master/model.cpp): `model.cpp`
- [Mesh attributes](https://github.com/ssloy/tinyrenderer/blob/master/model.cpp): `model.cpp`
- [Model textures](https://github.com/ssloy/tinyrenderer/blob/master/model.cpp): `model.cpp`
- [TGA image I/O](https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp): `tgaimage.cpp`
- [Rendered TGA](https://github.com/ssloy/tinyrenderer/blob/master/tgaimage.cpp): `tgaimage.cpp`

### Math foundation

- [Vectors and matrices](https://github.com/ssloy/tinyrenderer/blob/master/geometry.h): `geometry.h`

### Other components

- **User**

## Connections

- User → Render entry point: supplies model paths (evidence: `README.md`)
- Render entry point → OBJ model loader: loads models (evidence: `main.cpp`)
- OBJ model loader → Mesh attributes: parses attributes (evidence: `model.cpp`)
- OBJ model loader → Model textures: loads maps (evidence: `model.cpp`)
- OBJ model loader → TGA image I/O: reads texture files (evidence: `model.cpp`)
- Render entry point → Camera transforms: sets camera (evidence: `main.cpp`)
- Render entry point → Phong shader: constructs shader (evidence: `main.cpp`)
- Phong shader → OBJ model loader: reads mesh and maps (evidence: `main.cpp`)
- Render entry point → Triangle rasterizer: rasterizes triangles (evidence: `main.cpp`)
- Triangle rasterizer → Phong shader: shades fragments (evidence: `our_gl.cpp`)
- Triangle rasterizer → Depth buffer: tests and updates depth (evidence: `our_gl.cpp`)
- Triangle rasterizer → Framebuffer: writes pixels (evidence: `our_gl.cpp`)
- Render entry point → Framebuffer: creates image (evidence: `main.cpp`)
- Render entry point → Rendered TGA: writes TGA (evidence: `main.cpp`)
- Framebuffer → TGA image I/O: uses image storage (evidence: `tgaimage.cpp`)
- Camera transforms → Vectors and matrices: uses matrix math (evidence: `our_gl.cpp`)
- Triangle rasterizer → Vectors and matrices: uses vector math (evidence: `our_gl.cpp`)
- Phong shader → Vectors and matrices: transforms attributes (evidence: `main.cpp`)
