I have list of models and transform matrix for each of them. Some of models are flipped along X or Y or Z axis. This meshes will be rendered wrong, back face is rendered instead of front.

I tried to use glFrontFace(GL_CW) and that makes wrong models fixed but previous correct models are wrong.

How can I fix this? Can I detect from transform matrix which models need glFrontFace switch?

Right cube and sphere are normal and left are flipped

enter image description here


Yes you can detect this. If the determinant of the upper-left 3x3 part of the transformation matrix is negative, your model is flipped.

Quoting this wikipedia page http://en.wikipedia.org/wiki/Back-face_culling:

An odd number of reflections will leave triangle facing the other side, as if exactly after one reflection. Transformations containing an odd number of reflections always have negative scaling factor, likewise scaling factor is positive if there are no reflections or even number of them. Scaling factor of a transformation is computed by determinant of its matrix.

  • \$\begingroup\$ Checked and it is working. Is it common to switch front face or there is other more standard way to do this? \$\endgroup\$ Mar 15 '15 at 8:56
  • \$\begingroup\$ As far as I know the options are either to do it this way or create a copy of the index buffer with reversed vertex order. If you are rendering reflections, you only need to change the winding order one time if you render all reflected models at once. \$\endgroup\$
    – msell
    Mar 15 '15 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .