Master the fundamental concepts of software rasterizer through this focused micro-challenge.
When multiple triangles overlap on screen, which one is visible? The z-buffer (depth buffer), invented independently by Wolfgang Straßer and Edwin Catmull in 1974, solves this with a second buffer parallel to the color framebuffer.
Algorithm:
The z-buffer operates in screen space after vertex transformation. Each vertex carries (x, y, z) in normalized device coordinates where z typically runs 0 (near) to 1 (far).
cLoading…
For example, a red triangle at z=0.3 and a blue triangle at z=0.7 both covering pixel (5,5): the red triangle wins because 0.3 < 0.7. Z-fighting occurs when two surfaces are nearly equal in depth; limited float precision makes them flicker. Perspective-correct interpolation uses 1/z, not linear z, for accurate results under projection.
You will implement a 10x10 z-buffer with two overlapping triangles and print the final framebuffer colors. This task requires depth testing on every covered pixel. Z-buffering is the visibility algorithm behind Quake through Unreal Engine 5, and z-fighting bugs appear in every graphics programmer's career eventually.
Write a C program that implements a z-buffer for two overlapping triangles.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works