# lighting: polygons vs spheres

This topic is 5070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, a beginner's problem: my spheres are illuminated well, but my polygons are always dark on one side - no matter if I draw them clockwise or counterclockwise. I tried to place lights all around, but that didn't work. Maybe I have to define normal vectors for the polygons? If yes: how?

##### Share on other sites
The problem is that standard OpenGL lighting is per-vertex. So unless you have a highly-tessellated model (such as a sphere), you won't get accurate lighting results. I'm assuming that the polygons you're drawing are single triangles or quads, of course.

If you're looking for a way to define polygon normals, just take three points on the polygon and take the cross product of them to get a face normal, normalize it, and pass it to glNormal3f().

// Assuming vec3_t is a 3D vector object with overloaded operators.void GetFaceNormal(const vec3_t& p0, const vec3_t& p1, const vec3_t& p2){    vec3_t v0 = p1-p0;    vec3_t v1 = p2-p0;    vec3_t cross = CrossProduct(v0, v1);    cross.Normalize();    glNormal3f(cross.x, cross.y, cross.z);}

The function CrossProduct() takes two vector objects as arguments and returns the cross product of them (another vector).

-david-

##### Share on other sites
If I'm understanding you correctly then the problem is nothing to do with per-vertex lighting (although that may be another problem you have) but the fact that OpenGL lighting by default is one-sided. If you want to draw a two sided polygon, either draw it twice with back face culling enabled, one face pointing each way, or call glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);.

Enigma

##### Share on other sites
I think the problem is made pretty clear from the outset.

Quote:
 Original post by soilentHagebuttenteeMaybe I have to define normal vectors for the polygons? If yes: how?

Yes, you do have to define normal vectors.

You do this with the glNormal*() functions, for example glNormal3f(0.0f, 0.0f, 1.0f);

Hope this helps.

##### Share on other sites
Yeah, glNormal*() did the job! Thanks a lot!

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632988
• Total Posts
3009738
• ### Who's Online (See full list)

There are no registered users currently online

×