Lighting objects

I am at a point where I am lighting objects now and I noticed that if you creat one light source(diffuse, ambient, position), and you draw two different cubes, one using the command glutSolidCube, and the other using GL_QUADS, and rotate both of them the lighting have very different effects. the one with glutSolidCube reacts fine to the light, but the one with GL_QUADS gets dark once it rotates a certain amount, then lights up again, and it recures with every full rotation. can somebody explain this.
same results with nehes lighting tutorial

You need to build vertex normals in order to perform lighting! They are specified with glNormal*(*) and tell opengl in which direction the vertex is “pointing”. For a cube, you will want flat shading, which means that the normal for every of the 4 vertices of the quad are the same, which will get you sharp edges. You can get the normal with a crossproduct of two adjacent edges of the quad. Note that the crossproduct is a right handed system, and that the vectors given to opengl must have the length one.

thanks for you help, I got it working now. here is what i did:







this is the first time doing normals in openGL, is normal just a vector that is perpendicular and pointed in the front direction of a plane? when I did a search, there is a lot( alot is not a word ) of talk of calculating normals, why calculated them if you can tell by looking at the plane? is there something more to this?

Yes, there are basically two different important types of normals. Face normals, and vertex normals. It is not always obvious what a vertex normal is, so you calculate them using the face normals and connectivity info.

can you please give me an example of a vertex normal and explain its applications??

When lighting with plane normals, you will always be able to distinguish the faces (think of a sphere for this example).
Now, in opengl you can average the normals in a certain vertex. So you have calculated the lighting per vertex. Then opengl interpolates the resulting vertex color over the face. Thus, you have a “smooth” looking sphere which you couldn’t get with a normal per face. You will still be able to see the edges at the outline of the sphere though…
This technuiqe is called “Gouraud-shading”.