PDA

View Full Version : Understanding Opengl Lights....



Bruno
03-22-2001, 06:31 AM
Hi

I have been tryng to implement dynamic lighting in my engine using opengl lights, but i'm having some problems understanding the way they work..

This piece of code :

GLfloat LightAmbient[]={0.5,0.5,0.5,1.0f};
GLfloat lightSpecular[] = {0.5, 0.5, 0.5, 1.0f} ;

diffuse_light[0] = temp->r;
diffuse_light[1] = temp->g;
diffuse_light[2] = temp->b;
diffuse_light[3] = 1.0;

position[0] = Dluz[0];
position[1] = Dluz[1];
position[2] = Dluz[2];
position[3] = 1.0;


diffuse_light[3] = 1.0;

glLightfv(GL_LIGHT0,GL_POSITION,position);
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0,GL_SPECULAR,diffuse_light);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.7);

This works correctly.., but.., in this case i have a green light, and my object is allways green, but as the object goes far from the light, the object should get iluminated only by the ambient light, in this case white.The normals are ok, they are not the problem, i think the problem might be in having an ATTENUATION of 0.7.., however the bigger the value, the darker the scene.
In conclusion, how can i make a positional light, of any color, cast light only when the object near it,and if it's not, to get the color of the ambient light ?

thnks,

Bruno