This is the basic implementation of the z-buffer algorithm .
Suppose the depth buffer is a matrix d;
for(each polygon P)
for(each pixel (X, Y) on the polygon)
depth_variable = depth of P at (X, Y);
if(depth < d[X][Y])
color_variable = color of P at (X, Y);
set the pixel color at (X, ...