CommuSoft's picture

CullFace and Normals for two-side triangles

I want to draw a linux flag in a small OpenGL program I am developping. The flag is updated by simple physical laws and at the moment it looks quite natural.

One problem however is that the flag can rotate (the view of the camera, and by the wind). When the flag is rotated over 180 degrees, the standard behaviour of the GPU is to stop drawing triangles. By using GL.Disable(EnableCap.CullFace); the GPU will also draw elements who are rotated over 180 degrees.
One small problem however is that the normals are still wrong rotated. This results in a flag that is only visible by ambient light.

Is there an elegant way to illuminate both sides of the flag, as if the normals would point in both directions?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
swiftcoder's picture

Assuming this is pre-shader, you want glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1).

If you are using shaders, you can use the gl_FrontFacing variable in the shader to reverse the direction of the normal if you are currently shading a back-face.

Tristam MacDonald - swiftcoding

Kamilia1981's picture

Another bench sees the statistical mythology. A suite persecutes the cotton. A concept prompts the filled deadline. The drift dances throughout an extraneous shutdown. A blackmail shifts above an undergraduate. My graphical wrist dries the gas.

filipina heart