• Advertisement
Sign in to follow this  

Light Issue

This topic is 3270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement