wrong shading

I have a modell which consists of around 400 triangles. I defined one light but all triangles have the same shading/color.

I want that triangles upside up are different (lighter) from triangles upside down(darker).

thanks for hints ToP

Check the winding of your polygons - that is, the winding will make a difference to normal generation. And if you aren’t specifying normals, you need to enable opengl autonormal generation.

I am quite sure that the normals are set correctly. Guess, I need to discribe my problem better: All triangles, even those with a totally different orientation in space, have the same color shading. That means, texture/relief cannot be seen. I want my objects having shaded colors so that you have the impression of a 3D space. To say, each triangle gets his own shading depending on its position to the light.

And you have enabled one light and lighting?

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

if you set that and still doenst get another shading i bet its the normals.

You say you are “quite sure the normals are set correctly”, but the problem you describe kind of sounds like all the normals are the same.

Just to be sure, you are doing something like this, right?

glBegin(GL_TRIANGLES);
foreach(triangle in triangleList)
{
glNormal3fv(triangle.normal);
glVertex3fv(triangle.vertex);
}
glEnd();

If light settings and normals are all correct, you may try this.

glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0f);

Originally posted by Robbo:

Check the winding of your polygons - that is, the winding will make a difference to normal generation. And if you aren’t specifying normals, you need to enable opengl autonormal generation.

Wow. Interesting OpenGL feature. Can You tell me the name of this fantastic extension, which generates normals for me?

Michalek

Since it doesnt exists for triangles, i bet you never get any name for it

the autonormals are only for high order surface generation.

I donot create normals, they ar defines itself through 3 points?

glBegin(GL_TRIANGLES);
for (i = 1; i < triangles; i++)
{
glVertex3f(P1.x, P1.y,P1.z);
glVertex3f(P2.x, P2.y,P2.z);
glVertex3f(P3.x, P3.y,P3.z);
}
glEnd();

my lightsettings are this:

GLfloat ambient[] = {1.0, 1.0, 1.0, 1.0};
GLfloat position[] = {-500.0, 500.0, 900.0, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 0.5, 1.0};
GLfloat mat_shininess[] = {10.0};

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_POSITION, position);

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

Maybe that this is a problem with material or lightposition?

You must define your own normals, opengl will not create them. You get the same lighting on all faces becourse of that… Opengl only calculates the light with the normals, and since you dont give some new to it, the last sent normal ( or default (0,0,1) ) are set for all your vertices.

then its also good to set all material and light values, even if some are default…

[This message has been edited by Mazy (edited 07-15-2003).]