Skip to main content
gamedev.net
🔒 Locked

Light Issue

Started by sajis Mar 12, 2009 at 5:30 AM 1 replies 1.4k views
Original Post
sajis
sajis
Hello Forum, I have a single light source. And that very same source will be changed to different light type(Directional,Point And Spot) .The choice will be provided from the user interface. And i m setting the light properties as follows: ***************** void GLWidget::loadSpotLight() { glLightfv(GL_LIGHT0,GL_POSITION,lightPos); glLightfv(GL_LIGHT0,GL_DIFFUSE,lightKd); glLightfv(GL_LIGHT0,GL_SPECULAR,lightKs); glLightfv(GL_LIGHT0,GL_AMBIENT,lightKa); glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotDir); //set the attenuation facetor for point light /* glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,2.0); glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,1.0); glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.5); */ glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,14.0); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } ****************' Before loading the light i am disabling the light that may be set previously ******************** void GLWidget::unloadLights() { //unload all the lights that //are already defined if(glIsEnabled(GL_LIGHTING)) { if(glIsEnabled(GL_LIGHT0)) { glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); } } } ******************* When i change from one light to another light type i do not see the expected output Any hint would be of great help Regards Sajjad
mobeen
mobeen
Quote:
Original post by sajis
Hello Forum,

I have a single light source. And that very same source will be changed to different light type(Directional,Point And Spot) .The choice will be provided from the user interface.

When i change from one light to another light type i do not see the expected output

Any hint would be of great help

Regards
Sajjad


Hi,
The only thing i can point out is the call to glEnable(GL_LIGHTING) and glEnable(GL_LIGHT0); they must be called first and then the parameters must be set.
void GLWidget::loadSpotLight(){glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glLightfv(GL_LIGHT0,GL_POSITION,lightPos);glLightfv(GL_LIGHT0,GL_DIFFUSE,lightKd);glLightfv(GL_LIGHT0,GL_SPECULAR,lightKs);glLightfv(GL_LIGHT0,GL_AMBIENT,lightKa);glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotDir);//set the attenuation facetor for point light/*glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,2.0);glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,1.0);glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,0.5);*/glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,14.0);}

See if this works.

Thanks,
Mobeen
Proud to be a PAKISTANI.
sajis
sajis
Thanks


There is another issue that i want to query about


Is there any opengl query function that find out the kind of light that is currently active.

I have found that there is a glGet(-....) function to query if a particular light GL_LIGHTi

is enabled or not.


I want to if that particular light is point, directional or spot light


Regards
Sajjad

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.