Advertisement

Info about Lighting

Started by November 24, 2003 11:49 AM
2 comments, last by San Vegeta 21 years, 3 months ago
I have a problem: I''m able to turn on the lights in my program, but I can''t turn them off When the user press a key (0..7, I have 8 lights) a function checks the key''s number and call TurnLight() with the right parameter. Do you think it''s wrong? What should I do to be able to turn on and off the lights in a program? Thank you for your help void TurnLight(int number) { GLenum L[] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7}; if(LC.LightVector[number].present) { //it exists if(LC.LightVector[number].activated) { //it''s activated glDisable(L[number]); LC.LightVector[number].activated = false; } else { //it''s deactivated glLightfv(L[number], GL_AMBIENT, LC.LightVector[number].a); glLightfv(L[number], GL_DIFFUSE, LC.LightVector[number].d); glLightfv(L[number], GL_SPECULAR, LC.LightVector[number].s); glLightfv(L[number], GL_POSITION, LC.LightVector[number].p); glEnable(L[number]); } glutPostRedisplay(); } }
Bruno
void TurnLight(int number) {   GLenum L[] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3,GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};   if(LC.LightVector[number].present)    {      if(LC.LightVector[number].activated)       {         glDisable(L[number]);         LC.LightVector[number].activated = false;      }       else       {         glLightfv(L[number], GL_AMBIENT, LC.LightVector[number].a);         glLightfv(L[number], GL_DIFFUSE, LC.LightVector[number].d);         glLightfv(L[number], GL_SPECULAR, LC.LightVector[number].s);         glLightfv(L[number], GL_POSITION, LC.LightVector[number].p);         glEnable(L[number]);         LC.LightVector[number].activated = true;      }   glutPostRedisplay();   }}   


Don't forget to initialize your light states (glEnable/Disable) and 'LC.LightVector[number].activated' on programm start.

[edited by - Wildfire on November 24, 2003 1:37:23 PM]
How do I set my laser printer on stun?
Advertisement
*blush* I feel stupid... what a stupid error...

quote:

Don''t forget to initialize your light states (glEnable/Disable) and ''LC.LightVector[number].activated'' on programm start.



What do u mean? At the moment the scene is unlit, when I press a key I activate the selected light.

Thank you for your help my friend!
Bruno
Glad I could help And don''t feel stupid, the "obvious errors" are usually the hardest to find.

quote:

What do u mean? At the moment the scene is unlit, when I press a key I activate the selected light.


I just meant adding something like
for (number=0; number  < maxLights; number++){   glDisable(L[number]);   LC.LightVector[number].activated   =false;} 

to the startup code of your application, so that all lights are in a defined state. That''s to make sure the state of the light and LightVector match Otherwise it could happen that ''activated'' says off, while the light is on.
How do I set my laser printer on stun?

This topic is closed to new replies.

Advertisement