ランキングに戻る

ssloy/tinyrenderer

C++haqr.eu/tinyrenderer/

A brief computer graphics / rendering course

openglc-plus-pluspicturegraphicssoftware-renderingshadersrenderinglearningfunimagespixelscomputer-graphics
スター成長
スター
23.9k
フォーク
2.3k
週間成長
Issue
2
10k20k
2015年1月2018年11月2022年9月2026年7月
README

Software rendering in 500 lines of bare C++

The code itself is of little interest. Check the course notes:

  1. Introduction
  2. Bresenham’s line drawing algorithm
  3. Triangle rasterization
  4. Primer on barycentric coordinates
  5. Hidden faces removal
  6. A crude (but simple) approach to camera handling
  7. Better camera handling
  8. Shading
  9. More data!
  10. Tangent space normal mapping
  11. Shadow mapping
  12. Indirect lighting
  13. Bonus: toon shading
  14. Afterword

In this series of articles, I aim to demonstrate how OpenGL, Vulkan, Metal, and DirectX work by writing a simplified clone from scratch. Surprisingly, many people struggle with the initial hurdle of learning a 3D graphics API. To help with this, I have prepared a short series of lectures, after which my students are able to produce quite capable renderers.

The task is as follows: using no third-party libraries (especially graphics-related ones), we will generate an image like this:

Warning: This is a training material that loosely follows the structure of modern 3D graphics libraries. It is a software renderer. I do not intend to show how to write GPU applications — I want to show how they work. I firmly believe that understanding this is essential for writing efficient applications using 3D libraries.

The starting point

The final code consists of about 500 lines. My students typically require 10 to 20 hours of programming to start producing such renderers. The input is a 3D model composed of a triangulated mesh and textures. The output is a rendereding. There is no graphical interface, the program simply generates an image.

To minimize external dependencies, I provide my students with a single class for handling TGA files — one of the simplest formats supporting RGB, RGBA, and grayscale images. This serves as our foundation for image manipulation. At the beginning, the only available functionality (besides loading and saving images) is the ability to set the color of a single pixel.

There are no built-in functions for drawing line segments or triangles — we will implement all of this manually. While I provide my own source code, written alongside my students, I do not recommend using it directly, as doing the work yourself is essential to understanding the concepts. The complete code is available on github, and you can find the initial source code I provide to my students here. Behold, here is the starting point:

#include "tgaimage.h"

constexpr TGAColor white   = {255, 255, 255, 255}; // attention, BGRA order
constexpr TGAColor green   = {  0, 255,   0, 255};
constexpr TGAColor red     = {  0,   0, 255, 255};
constexpr TGAColor blue    = {255, 128,  64, 255};
constexpr TGAColor yellow  = {  0, 200, 255, 255};

int main(int argc, char** argv) {
    constexpr int width  = 64; 
    constexpr int height = 64; 
    TGAImage framebuffer(width, height, TGAImage::RGB);

    int ax =  7, ay =  3;  
    int bx = 12, by = 37; 
    int cx = 62, cy = 53; 

    framebuffer.set(ax, ay, white);
    framebuffer.set(bx, by, white);
    framebuffer.set(cx, cy, white);

    framebuffer.write_tga_file("framebuffer.tga");
    return 0;
}

It produces the 64x64 image framebuffer.tga, here I scaled it for better readability:

Teaser: few examples made with the renderer

Compilation

git clone https://github.com/ssloy/tinyrenderer.git &&
cd tinyrenderer &&
cmake -Bbuild &&
cmake --build build -j &&
build/tinyrenderer obj/diablo3_pose/diablo3_pose.obj obj/floor.obj

The rendered image is saved to framebuffer.tga.

関連リポジトリ
alacritty/alacritty

A cross-platform, OpenGL terminal emulator.

Rustcrates.ioApache License 2.0terminal-emulatorsopengl
alacritty.org
65k3.5k
kovidgoyal/kitty

If you live in the terminal, kitty is made for you! Cross-platform, fast, feature-rich, GPU based.

PythonPyPIGNU General Public License v3.0terminal-emulatorsopengl
sw.kovidgoyal.net/kitty/
34k1.4k
raysan5/raylib

A simple and easy-to-use library to enjoy videogames programming

Czlib Licenseraylibc
raylib.com
34k3.2k
google/filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2

C++Apache License 2.0pbrgraphics
google.github.io/filament/
20.3k2.2k
lettier/3d-game-shaders-for-beginners

🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.

C++shaders3d
lettier.github.io/3d-game-shaders-for-beginners/index.html
19.8k1.5k
RPCS3/rpcs3

PlayStation 3 emulator and debugger

C++GNU General Public License v2.0assembly-languagecpp
rpcs3.net
19.2k2.3k
gfx-rs/wgpu

A cross-platform, safe, pure-Rust graphics API.

Rustcrates.ioApache License 2.0webgpurust
wgpu.rs
17.6k1.4k
kitao/pyxel

A retro game engine for Python

Rustcrates.ioOthergamegame-development
17.6k929
bkaradzic/bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.

CBSD 2-Clause "Simplified" Licenseenginerendering
bkaradzic.github.io/bgfx/overview.html
17.3k2.1k
OpenRCT2/OpenRCT2

An open source re-implementation of RollerCoaster Tycoon 2 🎢

C++GNU General Public License v3.0c-plus-plusgame
openrct2.io
16k1.9k
glfw/glfw

A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input

Czlib Licensevulkanopengl
glfw.org
15.2k5.9k
SFTtech/openage

Clone of the Age of Empires II engine 🚀

PythonPyPIOthergameengine
openage.dev
14.3k1.3k