Problems with lighting


I have al little problem with Lighting.
when i put a object on screen, colored red

the triangle is displayed red. when i put a white lightsource in the scene, the object is displayed only black and white, independend of: normal, diffuse, secular, ambient values. (gl_smooth is on)
the next problem is, if a triangle is on the same line (say, middle on z-axis, lightsource in 0,0,0) the triangle BEHIND this is also lighting…?
ligthing is my last big opengl-problem :slight_smile:

thanks for help,


Do you setup material properties, and not only light properties? glColor*() got no effect when lighing is on.

And second, do you mean that you have two triangles in a row, and you expect the one close to the light to cast a shadow on the other one? If so, then forget it. No offense, but shadows is up to you do do. OpenGL draws whatever you want it to draw, and don’t care about what has already been drawn or what will be drawn.

and the Normals???

Before drawing the polygon you should give it a normal like this:
This face is ‘looking’ to the dir X=1, Y=0, Z=0

You can use glColor if you enable Color Material (see glEnable(GL_COLOR_MATERIAL)) instead of glMaterial, its easier to play with maybe.

And yes, surface normals are absolutelly needed. You have to provide them, since opengl wont calculate them. GLU functions will generate normals for the GLU primitives if you ask for it.

Yeah, this helped a lot. i forgot to say that i use glNormals…

btw: I’m now trying to make a shadow-system.