Ortho & Perspective = z-fighting

This is what i do:

  1. Setup perspective view
  2. Render a z-only pass
  3. render the level
  4. copy that image into a texture
  5. push projection-matrix
  6. setup ortho view
  7. theoretically distort the image (not done at the moment)
  8. pop projection matrix
  9. render my level lit, etc.
  10. add the distortet texture

I setup my ortho-view this way:

  1. Camera.PushProjectionMatrix ();
  2. glMatrixMode(GL_PROJECTION);
  3. glLoadIdentity();
  4. glOrtho (0, 1024, 0, 768, Camera.GetNearPlane (), Camera.GetFarPlane ());
  5. glMatrixMode(GL_MODELVIEW);

… theoretically do some stuff (but NOTHING gets done, yet)

  1. Camera.PopProjectionMatrix ();

If i comment out line 4 everything works fine. But with it in the code, i get z-fighting afterwards, when i do multiple passes in perspective mode.
I swear, between push, ortho and pop, there is NOTHING done.
I thought maybe glOrtho changed the depthfunc, and made sure it is set to GL_LEQUAL, but that doesn´t fix the problem.

I really think that´s strange. A matrix should not change a bit (take that literally) when it gets pushed and popped.
And therefore the computations should not differ afterwards.
I have to do those operations in that order. So i have to switch between ortho and perspective view in the middle of the frame.

Any suggestions, or is this a driver bug?

Jan.

Well, glOrtho is not the bad guy. Actually ANY change to the projection-matrix yields to z-fighting.

For example, this code

glMatrixMode(GL_PROJECTION);
glPushMatrix ();
glLoadIdentity();
glPopMatrix ();

gives me z-fighting, whereas this code

glMatrixMode(GL_PROJECTION);
glPushMatrix ();
glPopMatrix ();

doesn´t.

Strange, hu?

Jan.

can you also post the code for Camera.PopProjectionMatrix (); ?

Nothing easier than that:

void CAMERA3D::PushProjectionMatrix (void)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix ();
glMatrixMode(GL_MODELVIEW);
}

void CAMERA3D::PopProjectionMatrix (void)
{
glMatrixMode(GL_PROJECTION);
glPopMatrix ();
glMatrixMode(GL_MODELVIEW);
}