Multiple lights not working
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!
I have a Lights objects that holds an array of Light objects. Lights constructor is as follows:
Light constructor is defined as follows:
Light renderer is defined as follows:
glEnable(GL_LIGHTING); //Enable LightingglGetIntegerv(GL_MAX_LIGHTS, &maxLights); //Get the maximum number of lightslightsArray = new Light[maxLights]; //Array a Light objectsglLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);//Set lighting model to both sides//Initialise each light elementfor(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(); }}
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement