Before incorporating a z-buffer into my rasterization routine, I needed a way to interpolate z-coordinate values. I read some articles online (Chris Hecker's perspective correct texture mapping was a good one). I ended up writing a general function that lets you calculate interpolants using gradiants. Gradiants in screenspace represent the change in an interpolants (such a z-value) that occurs when you move up and down the x or y axis. These remain constant across the triangle so you only have to calculate them once. Whats more, the method of generating a gradiant can be generalized to work with other interpolants (e.g. colour, texture coordinates).
This is a screenshot before depth testing...
After adding z-interpolation and adding the z-buffer, I get the following...
When seen in motion, there are some artifacts (sometimes very tiny cracks are visible between triangles and there is some minor flickering).