Sign in to follow this  

Multiple lights not working

This topic is 4304 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

Ji guys, I have a proble when trying to use more than 1 light. I can enable GL_LIGHT0 ok, but everyother light will not work. I have a maximum of 8 lights to work with, I know cos I checked. Does any1 know what could be wrong? Thanks for any help given!

Share this post


Link to post
Share on other sites
I have a Lights objects that holds an array of Light objects. Lights constructor is as follows:


glEnable(GL_LIGHTING); //Enable Lighting
glGetIntegerv(GL_MAX_LIGHTS, &maxLights); //Get the maximum number of lights
lightsArray = new Light[maxLights]; //Array a Light objects
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);//Set lighting model to both sides

//Initialise each light element
for(int i=0; i<maxLights; i++)
{
lightsArray[i] = Light(i, SceneVector3(0.0,0.0,0.0), Positional);
}



Light constructor is defined as follows:


Light::Light(GLenum lightNo, const SceneVector3& position, LightType type)
{
lightNumber = lightNo;
openGLLightNumber = 0; //this light number
openGLLightNumber =
(GLenum)(GL_LIGHT0 + (GLenum)lightNo); //openGL number for light
enabled = false; //initialise light to off
lightPosition = position; //Posiotion of light
nonLitColour = SceneColour::WHITE;
ambientColour = SceneColour::WHITE;
diffuseColour = SceneColour::WHITE;
specularColour = SceneColour::WHITE;
}



Light renderer is defined as follows:


void Light::render()
{
if(enabled)
{
glPushMatrix();
float ligthInfo[4] = { translationMatrix.getXTranslationValue(), translationMatrix.getYTranslationValue(),
translationMatrix.getZTranslationValue(),
1.0};//TODO: change this, positional/directional

glLightfv(lightNumber, GL_POSITION, ligthInfo);
float lightColour[4] = {ambientColour.x, ambientColour.y,
ambientColour.z, ambientColour.a};

glColor3fv(lightColour);

//render something to denote position of light

glPopMatrix();
}
}

Share this post


Link to post
Share on other sites
A short reply wud be :
change
glLightfv(lightNumber, GL_POSITION, ligthInfo);
to
glLightfv( openGLLightNumber , GL_POSITION , lightInfo );
Thats a definite bug i see there.
I dont see any think wrong any place else.

Explanation:
u pass i to the Light() constructor as the first argument.
Inside the constructor u are setting lightNumber to i and openGLLightNumber to the appropriate GL_LIGHTn so if no more code is changin the variable lightnumber u are passing the wrong value to glLightfv

Share this post


Link to post
Share on other sites

This topic is 4304 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this