I am trying to implement lighting into a demo I am working on but even though I feel I understand the way the light model works, it doesn’t seem to want to. I am using the following code in my Init() function, when it then comes to the renderscene function, the models I draw are all black instead of being the colour declared. I have removed all the texture mapping in the scene, tried using the (GL_COLOR_MATERIAL) function and played around with the colour of the light but never seems to make any difference either.
I was wondering if anyone out there has ever come across a similar problem and if so, how did it happen?
You seem to provide a direction light for your light pos vector. Ie if light pos ends with 0, than you should specify it is a direction vector for parallel light.
If you wanted a positional light, then you should set the last component to 1.
If your going for directional light, try passing a normalized direction.
– sorry about the multiple posts, they didn’t appear on my screen until today for some reason -
Thanks Maximian, does that mean that everthing in the scene would be lit from one side - that is what I am after. I don’t quite understand what you mean by declare a normalised vector though, I have added a 1 to the end of the position vector but it has no effect :o( Where would I position the light source if I wanted directional? Would it need to be really far away?
A directional light source, generate parellel light rays, which would create the effect you would like. A positional light is like
a small light source, so that the position, ie the distance from the point light source to an object determines how brightly the object is lit.
For a directional light source, only the direction of the light source, and the direction of the face of a model are important.
For a directional light, you should set the last element to 0, not 1. But when you pass
the direction vector you should normalize.
Also remember a direction light, does not have a position. It is not located at some point, x,y,z. A directional light simply says that parallel light rays will shine along some direction. So <0,1,0> means light rays will shine toward the pos y direction.
That is you need to carefully pick the direction of your light source.