# Easily/automatically flip normals?

## Recommended Posts

I've read that a somewhat effective approach to rendering (convex) transparent objects correctly is to first (disable z-write, of course, and then) cull the front faces and draw the object, then cull the back faces and draw it:
if (d->blendMode != BM_NONE) {
renderState.setCullFace( GL_FRONT );
glDrawRangeElements( GL_TRIANGLES, 0, d->vertCount-1, d->triCount*3, GL_UNSIGNED_INT, BUFFER_OFFSET( d->iboOffset ) );
}
renderState.setCullFace( GL_BACK );
glDrawRangeElements( GL_TRIANGLES, 0, d->vertCount-1, d->triCount*3, GL_UNSIGNED_INT, BUFFER_OFFSET( d->iboOffset ) );
However, this simply flips which side of the polygon is drawn - it doesn't affect the normals, so lighting will be "backwards" on the inside faces. This is especially an issue with objects use glAlphaFunc because most of the object looks like a normal opaque object, but the lighting would just be screwy looking. I'm guessing there isn't any like... er, glFlipNormals( true ), or glMultNormals( -1 ), is there, heh heh? Assuming not, any ideas of how to (somewhat) easily do this so that I won't have to redesign too much of my renderer? (Also, if you notice something strikingly wrong in my glDrawRangeElements calls, let me know, cause they crash for some reason. It probably isn't a problem with those lines though.)

##### Share on other sites
I believe OpenGL supports two-sided lighting; you can find an example here. (I've never tried it myself, so I can't guarantee that it would give the results you're looking for.)

Just as a side note, Direct3D doesn't offer support for two-sided lighting (via the FFP, at least), so that's something you'd probably need to consider if your renderer is cross-API.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628381
• Total Posts
2982359

• 10
• 9
• 15
• 24
• 11