   When to do polygon clipping?
  So, I'm writing a software rasterizer in a dos console for kicks and giggles, and everything looks great so far.  That is, until I started to view polygons close-up and at extreme angles.  I've been avoiding polygon clipping until now, since there wasn't a need for it until now.  The tutorial I followed mentions that I can clip in either 2 or 3 dimensions.  However, it also states:Quote:Objects that are very close will not just fall of the screen, they cause mayhem in the perspective formulas too. At the moment that Z (the depth of a vertex) changes sign, the screen coordinates will do the same, causing polygons to appear as random large nails on your screen. This can be solved by clipping the polygons against a plane, close to Z=0.... which I assume is the problem I'm observing.  But the question is, when do I perform the clipping?  At the moment, I'm clipping at z=nearPlane on the triangle level.  However, this does not fix the problem, as at the time of the clipping x and y components of the coordinates have already been transformed, and if their z component is, as the tutorial states, close to 0, then it causes "large nails on the screen."  So I assume clipping won't help in this case?  Also, I'm not very familiar with linear algebra, but I know enough to get around.  Is there a reason why OpenGL separates the transformation matrices from the viewport matrices?  Will I have to transform the vertices with the transformation matrix first, then perform clipping, then transform the results with the perspective matrix?  Or should I perform the clipping before I divide the Vector4 by its w component?Here's how I got it set up so far:Client supplies vertices and matrices in a OpenGL-immediate-mode fashionOn the call to "end," the vertices supplied by the client are transformed with the final matrix into screen coordinatesDepending on the mode specified by the client at the call to "begin," the vertices are drawn (polygon, triangles, quads)Per triangle, the polygon is clipped against the z-axisThe final polygon is renderedInternet cäeks for those who can help me out.Chairs!   
  You clip in clip space -- that is, after transforming by the world and projection matrices, and before the perspective division and the viewport transformation.   