View Full Version : Lighting effect with culling backface

06-08-2009, 12:43 PM
There are shadows in the lighting effect of the top graph, but there isn't in the bottom one.

The code between the top graph and the bottom graph is that the GL_CULL_FACE is enabled in the bottom one. e.g.,

The teapot and that object are rendered at the same time, in the same window, and with the same lighting conditions. However, the light effect of the teapot is pretty good in both conditions.

I don't know what the problem is. It seems the backface triangles reslut in the difference of lighting effect.

The sample code of lighting is as follows:


float fPos[] = {0, 1, 0, 0.f};
glLightfv(GL_LIGHT0, GL_POSITION, fPos0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, fDiffuse);

http://picasaweb.google.com/lh/photo/r0IomUGqOR8vlizXCr1FMA?authkey=Gv1sRgCJHo9PWdnInYV w&feat=directlink
Lighting effect image (http://picasaweb.google.com/lh/photo/r0IomUGqOR8vlizXCr1FMA?authkey=Gv1sRgCJHo9PWdnInYV w&feat=directlink)
Thanks so much for any suggestion.

06-09-2009, 12:54 PM
Since culling the back faces seems to fix the problem, it seems that drawing something in the top picture is wrong - you're drawing the dark grey bits over the lighter bits. I'm assuming the light is shining onto the side of the front of the objects, so the darker patches could be the far side of the cloud. These faces would be back facing. So...

Did you enable depth testing? If you did not, you could be drawing the backs of the far side of the cloud over the near side of the cloud in the top picture. In the bottom, since these faces are backwards, they are not getting drawn and the picture looks correct.

06-10-2009, 04:05 PM
Thanks so much for your reply.

I found the problem resulted from GL_POLYGON_OFFSET_FILL.
I enable it because I want to render polygon surface in FILL mode and LINE mode simutaneously. Although I only render in FILL mode in the picture, it seems GL_POLYGON_OFFSET_FILL should not used with lighting. I don't know if it is a known issue, or maybe I just don't know how to use it.

glPolygonOffset(2.0, 2.0);

I also find the larger the offset is, the worse the lighting effect will be.

Thanks again.