I'm writing a program where I have a little "polyman" guy dancing at 0,-3. I've colored him white, and am now trying to get a disco-like scene going, I have created a blue and red light, and am trying to alternate them by using a counter and and if and else statement. This is all in my renderscene
float ambientlight[] = {0.0,0.0,1.0,1.0};
float diffuselight[] = {1.0,1.0,1.0,1.0};
float specular[] = {1.0,1.0,1.0,1.0};
float lightpos[] = {0.0,10.0,0.0,1.0}; //light 1
float specref[]={1.0,1.0,1.0,1.0};
float spotdir[]={0.0,-10.0,0.0};
float rectX[6][5], rectY[6][5], rectZ[6][5];
float ambientlight2[] = {1.0,0.0,0.0,1.0};
float diffuselight2[] = {1.0,1.0,1.0,1.0};
float specular2[] = {1.0,1.0,1.0,1.0};
float lightpos2[] = {0.0,10.0,0.0,1.0}; //light 2
float specref2[]={1.0,1.0,1.0,1.0};
float spotdir2[]={0.0,-10.0,0.0};
glColor3f(1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,540,440);
glOrtho(-7.0,7.0,-7.0,7.0,5.0,-5.0);
glEnable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (counterForLights % 2 == 0) //if counter even
{
glLightfv(GL_LIGHT0, GL_POSITION,lightpos);
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientlight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuselight);
glLightfv(GL_LIGHT0,GL_SPECULAR, specular);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,10.0); //light 1
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,15.0);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,spotdir);
glEnable(GL_LIGHT0);
counterForLights++;
}
else //if counter odd
{
glLightfv(GL_LIGHT1,GL_AMBIENT,ambientlight2);
glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuselight2);
glLightfv(GL_LIGHT1,GL_SPECULAR, specular2);
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,10.0);
glLightf(GL_LIGHT1,GL_SPOT_EXPONENT,15.0); //light2
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spotdir2);
glEnable(GL_LIGHT1);
counterForLights++;
}
counterForLights is a global variable equalling 1. It runs, but doesn't ever show the red light, just the blue light. Any ideas of where I'm going wrong here?
Also, if you need to see anymore of my code just let me know! :)
Aucun commentaire:
Enregistrer un commentaire