include files | ||
---|---|---|
rasterize.hh | RasterizeTriangle() ,
the generic triangle rasterizer that will remain unmodified for the entire series;
updated in episode 3 to also include RasterizePolygon() | |
math.hh | Vector mathematics, used since episode 2 (examples 05 onwards) | |
view.hh | class View , used since episode 3 (refactoring) | |
slope.hh | class Slope , used since episode 3 (refactoring) | |
polygon_clip.hh | ClipPolygon() , used since episode 3 (refactoring) | |
polygon_draw.hh | DrawPolygon() , used since episode 3 (refactoring) | |
polygon_tesselate.hh | TesselateAndDraw() , used and also obsoleted since episode 3 (refactoring) | |
example programs | ||
00-test-singlecolor.cc | Example 00: (Episode 1 or P1) Single-color polygon renderer, proof of concept | |
01-test-singlecolor.cc | Example 01: (Episode 1 or P1) Single-color polygon renderer, after refactoring | |
02-test-rgb-scanlines.cc | Example 02: (Episode 1 or P1) Gouraud shading, before fixing | |
03-test-rgb-full.cc | Example 03: (Episode 1 or P1) Gouraud shading, after fixing | |
04-generic.cc | Example 04: (Episode 1 or P1) Gouraud shading, after refactoring | |
05-texture-flat.cc | Example 05: (Episode 2 or P2) Texture mapping (affine, 2D demo) | |
06-scene-flat.cc | Example 06: (Episode 2 or P2) Texture mapping (affine, 3D demo) | |
07-scene-perspective-corrected.cc | Example 07: (Episode 2 or P2) Texture mapping (perspective corrected, 3D demo) | |
08-scene-zbuffer.cc | Example 08: (Episode 2 or P2) Depth map (z-buffer) | |
09-scene-antialias-dither.cc | Example 09: (Episode 2 or P2) Bilinear filtering (approximated using quick dithering) | |
10-scene-antialias-interp.cc | Example 10: (Episode 2 or P2) Bilinear filtering (real, using linear interpolation) | |
11-scene-polygon.cc | Example 11: (Episode 2 or P2) Tesselation, so scene can be constructed from arbitrary convex polygons | |
12-scene-clip.cc | Example 12: (Episode 2 or P2) With clip planes | |
13-bonus.cc | Example 13: Higher resolution, the rounding error fix patch applied, backface culling enabled, dithering enabled | |
14-refactor.cc | Example 14: (Episode 3 or R) Refactored version | |
15-thatscene.cc | Example 15: (Episode 4 or L1) That scene (various versions, edit Plot() to enable/disable things like fog, edit LightCoord to enable moving lights) | |
16-lightmap.cc | Example 16: (Episode 5 or L2) Lightmap with RGB24 rendering | |
17-lightmap-rgb.cc | Example 17: (Episode 5 or L2) Lightmap with RGB96f rendering | |
off-screen include files | ||
mesh.hh | 00—04 | Off-screen code: CreateTriangleMesh() ,
creates the screen-filling mesh seen in first demonstrations |
mousemanip-part1.hh | 06 | Off-screen code: Mouse manipulation, used in episode 2 |
mousemanip-part2.hh | 06 | Off-screen code: Mouse manipulation, used in episode 2 |
bugfixes and feature additions | ||
patch-fix-rounding-error.txt | 04—13 | (Bugfix) A patch for fixing rounding errors that cause staircased textures even when bilinear filtering is used |
patch-fix-rounding-error2.txt | 14—17 | (Bugfix) A patch that corrects the earlier fix for rounding errors, now also fixing the lightmap camera position, together with other patches fixes the spurious streak artifacts |
patch-fix-diagonal-beams.txt | 17 | (Bugfix) A patch for fixing the “diagonal beams” in lightmap, which is caused by the rectilinear projection without compensating for said projection. Backstory in separate article |
patch-fix-clipping-seams.txt | 12—17 | (Bugfix) A patch for fixing seams between clipped polygons, addressing a bug that causes glitches in lightmaps and jitter to appear when rendering at low resolution |
patch-fix-view-edge.txt | 08—17 | (Bugfix) A patch for fixing the right and bottom edge of the viewport, addressing a bug that causes glitches in lightmaps and jitter in low resolution views |
patch-fix-view-nearclip.txt | 08—17 | (Bugfix) A patch for pulling the near clipping plane closer to camera, addressing a bug that causes glitches in lightmaps |
patch-lightmap-speed-hack.txt | 17 | (Feature) A patch that makes (most of) the lightmaps converge faster by calculating the first few iterations at a significantly reduced resolution and bilinearly interpolating to hide the fact |
17 | If you are not using the speed-hack patch, you need to add float half=.5f;
right before the line where the compiler complains about the missing identifier. | |
patch-add-bilinear-filtering.txt | 17 | (Feature) A patch that adds bilinear filtering in example 17. |
patch-fix-clang.txt | 17 | (Feature) A patch that formats some code differently to enable compilation on Clang 11. Not sure if those are bugs in my code or shortcomings in the compiler. Some of them seemed strange. |
git clone https://iki.fi/bisqwit/jkp/polytut/.git |
You can use this command to fetch the exact copy of the source code shown in the video at ~25 different phases. The repository contains about a hundred branches, which are numbered (biggest number=latest). This is not an accident. My workflow automatically generates a new branch every time I re-generate the video, and in each of these branches it creates a commit whenever the footage pauses. With some effort, you can thus get an impression of one aspect of the development progress of this series (since April 2020, when I added this feature). |
g++ 04-generic.cc -Wall -Wextra -pedantic -Ofast -std=c++20 $(pkg-config sdl2 --libs --cflags)
To run:
./a.out
Note: You will need GCC version 10.0.1 or Clang++ version 11 or newer to compile it.
You also need libSDL 2. (e.g. apt-get install libsdl2-dev
)
The pkg-config part inserts into the commandline
all the necessary options for compiling and linking,
even if your SDL2 is installed in an unconventional path.
If you use csh, replace $() with backticks.
GCC version 8 or 9 may also be used, provided that you change the following (these instructions are only valid for examples 04 and earlier):
-std=c++20
with -std=c++2a -fconcepts
#include <ranges>
and #include <numbers>
requires
clauses (six lines in rasterize.hh
, some trailing lines in the main example, some instances in math.hh
)std::numbers::pi_v<float>
with one of these: 4*std::atanf(1)
,
2*std::asinf(1)
,
2*std::acosf(0)
,
std::atan2f(0,-1)
(since example 06)std::ranges::range_value_t<decltype(points)>
with std::decay_t<decltype(*std::begin(points))>
(since example 11)std::views::all(points)
with points
(since example 11)γ
) with \u03B3
-std=c++2a
with -std=c++17
(this will cause warnings about lambda templates, ignore them)
-std=c++17
back to -std=c++2a
-fconcepts
auto
parameters into template
…typename
(no search&replace, requires you to actually know c++ syntax)std::apply
)