• Stars
    star
    20,126
  • Rank 1,255 (Top 0.03 %)
  • Language
    C++
  • License
    Other
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A brief computer graphics / rendering course

Tiny Renderer or how OpenGL works: software rendering in 500 lines of code

Check the wiki for the detailed lessons.

compilation

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

The rendered image is saved to framebuffer.tga.

You can open the project in Gitpod, a free online dev evironment for GitHub: Open in Gitpod

On open, the editor will compile & run the program as well as open the resulting image in the editor's preview. Just change the code in the editor and rerun the script (use the terminal's history) to see updated images.

The main idea

My source code is irrelevant. Read the wiki and implement your own renderer. Only when you suffer through all the tiny details you will learn what is going on.

In this series of articles, I want to show the way OpenGL works by writing its clone (a much simplified one). Surprisingly enough, I often meet people who cannot overcome the initial hurdle of learning OpenGL / DirectX. Thus, I have prepared a short series of lectures, after which my students show quite good renderers.

So, the task is formulated as follows: using no third-party libraries (especially graphic ones), get something like this picture:

Warning: this is a training material that will loosely repeat the structure of the OpenGL library. It will be a software renderer. I do not want to show how to write applications for OpenGL. I want to show how OpenGL works. I am deeply convinced that it is impossible to write efficient applications using 3D libraries without understanding this.

I will try to make the final code about 500 lines. My students need 10 to 20 programming hours to begin making such renderers. At the input, we get a test file with a polygonal wire + pictures with textures. At the output, we’ll get a rendered model. No graphical interface, the program simply generates an image.

Since the goal is to minimize external dependencies, I give my students just one class that allows working with TGA files. It’s one of the simplest formats that supports images in RGB/RGBA/black and white formats. So, as a starting point, we’ll obtain a simple way to work with pictures. You should note that the only functionality available at the very beginning (in addition to loading and saving images) is the capability to set the color of one pixel.

There are no functions for drawing line segments and triangles. We’ll have to do all of this by hand. I provide my source code that I write in parallel with students. But I would not recommend using it, as this doesn’t make sense. The entire code is available on github, and here you will find the source code I give to my students.

#include "tgaimage.h"
const TGAColor white = TGAColor(255, 255, 255, 255);
const TGAColor red   = TGAColor(255, 0,   0,   255);
int main(int argc, char** argv) {
        TGAImage image(100, 100, TGAImage::RGB);
        image.set(52, 41, red);
        image.write_tga_file("output.tga");`
        return 0;
}

output.tga should look something like this:

Teaser: few examples made with the renderer

More Repositories

1

tinyraytracer

A brief computer graphics / rendering course
C++
4,978
star
2

tinykaboom

A brief computer graphics / rendering course
C++
2,345
star
3

tinyraycaster

486 lines of C++: old-school FPS in a weekend
C++
1,884
star
4

triador

Ternary computer emulator
C++
227
star
5

glsltuto

GLSL shaders tutorial
C++
217
star
6

least-squares-course

By a programmer for programmers
TeX
189
star
7

tinycompiler

Writing a compiler in a week-end
Python
96
star
8

hellOGL

Yet another (but better) modern OpenGL hello world
C
82
star
9

sdl2-demo

sdl2 platformer game blank repository
C++
48
star
10

ultimaille

The ultimate mesh handling library
C
47
star
11

tutorials

C++
44
star
12

penny

3 servos, 10 dollars hexapod
HTML
31
star
13

invertible-maps

C++
25
star
14

stlbfgs

C++ L-BFGS implementation using plain STL
C++
24
star
15

neato-xv11-lidar

Protocol description and linux implementation
C++
23
star
16

instantangle

2D mesh deformation interactive demo
C
20
star
17

tinyrenderer-java

Just a java implementation of https://github.com/ssloy/tinyrenderer/wiki
Java
14
star
18

fast-and-tiny

A very basic raytracer in python
Python
10
star
19

QIS

Quasi-isometric stiffening C++ implementation
C++
9
star
20

quadruped

TRIK + dynamixel ax-12a
C++
7
star
21

harlequin

ZX spectrum 48k Harlequin Superfo clone
7
star
22

mathfun

C
6
star
23

winslow2d

Winslow elliptic smoothing for 2d unstructured triangular meshes
C++
6
star
24

ENSG

Support c++ code for lectures on numerical geology
Python
3
star
25

stroll

code example for bachelor programming class
C++
2
star
26

pentominos

L2 programmation avancée support
C++
1
star
27

ternary

triador hardware
C
1
star
28

NuPogodi

C++
1
star
29

ifs

iterated function systems small programs
C++
1
star
30

jfig2020

rendering contest entries
1
star