PDA

View Full Version : what's the difference about light(),& lightmode()



sosozcm
02-15-2011, 03:57 AM
the function glLightfv(GL_LIGHT0, GL_AMBIENT, ambient) can set the ambient light.
at the same time the function,glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient) can also set the ambient light. So what is the difference.

V-man
02-15-2011, 09:32 AM
GL_LIGHT_MODEL_AMBIENT adds ambient lighting whether lights are enabled or not.

The other one is part of the light's state. Each light has its own ambient term.

Aleksandar
02-15-2011, 12:37 PM
the function glLightfv(GL_LIGHT0, GL_AMBIENT, ambient) can set the ambient light.
Nope! That function sets the ambient component of LIGHT0. Isn't it obvious from the parameter list?


at the same time the function,glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient) can also set the ambient light. So what is the difference.
This function sets a GL_LIGHT_MODEL_AMBIENT parameter of "global" lighting model. As V-man said, you can have an illumination effect without any light source in your scene by setting this parameter to value different than 0. Be aware that GL_LIGHT_MODEL_AMBIENT interacts only with ambient component of the material.

GL_AMBIENT component of each particular light source also interacts with the ambient component of the material, but spotlight effects as well as attenuation affects this interaction.

If you have the chance, read chapter 5 from the Red book (OpenGL Programming Guide).