OpenGL clipping


I have a question concerning clipping in Opengl. By specifying a perspective projection matrix and a camera matrix, there should be the problem of vertices which are in the world space behind or on the plane parallel through the near plane and passing through the center of projection. In projective space those vertices have inverted order.

Ok, assume I have an eye frustum intersecting a quad in world space. 2 Vertices are in front of the frustum and 2 are behind. Those which are behind will get inverted (when I transform them on the CPU). This should change the orientation of the quads’ triangles due to the inversion.

However, if I use Opengl to transform those vertices, the plane is correctly transformed, i.e. the orientation of the triangles is maintained after projection. How is this possible? Does clipping play a role here? But then, clipping has to be performed in world space rather than in projective space, where the vertices are already wrongly transformed. Could anyone enlighten me on that?


The entire space behind the viewer is inverted, but it’s not an issue :slight_smile: . Follow the line(s) from behind the view position to in front of the view position and you’ll see that the polygon untwists as it moves across the singularity of the view position. Clip the polygon to the near plane (which is in front of the view position) and everything just works as you’d expect, and it can all be done in post-projection space.

Thanks for your reply!

Ok, I know, there is no problem in front of the near plane, but only behind. But how is Opengl doing that? Does then Opengl clip against the near plane in world space? Because to avoid this inversion problem it is too late to address this problem in the projective space.

You keep saying there is a problem, there isn’t! Honest! :slight_smile:

Clipping is done post-projection because it’s a simple matter of clipping to the post-projection space cube ( x, y and z are clipped to be between -w and +w, in OpenGL ). Clipping in world space is possible, but a pain, and there’s no need to do it.

Think about it again. Behind the view position polygons are inverted. But, the whole of the space behind the viewer is inverted. As lines cross the view position singularity, from behind to in front of the view position, they untwist the polygons to the correct orientation (“untwist” is a bad choice of term, “invert” would be better). Space in front of the view position is as you would expect. As long as you clip polygons before they go behind the view position they are the correct orientation. (Actually, you clip to the near plane because otherwise bad things happen when you do the perspective divide).

Hopefully this appalling ASCII art will help visualise things

In front of view position
 \         /
  \       /
   \-----/   near clip plane
    \   /
     \ /
     / \
    /   \
   /     \

Behind view position

Note that the near clip plane is in front of the view position somewhat. Now, lines passing from behind the view position to in front (and vice versa) will pass through the view position and end up inverted wrt the other side. That’s fine. As long as you’re only trying to render stuff that’s in front of the viewer (which, unless you fully understand projections, you should stick to) it isn’t a problem because everything is oriented the way you expect.

I guess I’m explaining this badly. For better explanations check out “Computer Graphics, Principles and Practice” by Foley, Van Dam, Feiner and Hughes (I always feel bad for Feiner and Hughes when they get called “et al”) or “3D Computer Graphics” by Alan Watt. Both books cover the perspective projection in decent detail, and explain things a lot better than I can :slight_smile:

Ok, I think I got it. Thanks a lot for your help!