Jump to content
  • Advertisement
Sign in to follow this  
Cacks

Multiple lights not working

This topic is 4520 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
Advertisement
Guest Anonymous Poster
can you post your code?

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 = 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!