The z-Buffer Algorithm
The z-Buffer algorithm is one of the most commonly used routines. It is simple, easy to implement, and is often found in hardware.
The idea behind it is uncomplicated: Assign a z-value to each polygon and then display the one (pixel by pixel) that has the smallest value.
There are some advantages and disadvantages to this:
Advantages:
Simple to use
Can be implemented easily in object or image sapce
Can be executed quickly, even with many polygons
Disadvantages:
Takes up a lot of memory
Can't do transparent surfaces without additional code
For example:
Consider these two polygons (right:edge-on left:head-on)
The computer would start (arbitrarily) with Polygon 1 and put it's depth value into the buffer. It would do the same for the next polygon, P2.
It will then check each overlapping pixel and check to see which one is closer to the viewer, and display the appropriate color.
This is a simplistic example, but the basic ideas are valid for polygons in any orientation and permutation (this algorithm will properly display polygons piercing one another, and polygons with conflicting depths, such as: