PDA

View Full Version : How to switch the light on scoreboard?



danzriba
03-14-2011, 09:21 AM
I have two problems.
First:
When I make a move with the cursor the light is changing from pic1 to pic2.

Second:
The light is shinning on the gameboard see pic2, but it's not shinning on the scoreboard above. I tried different light positions, but nothing happend.

void init(void)
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
glEnable(GL_LIGHT3);
glEnable(GL_LIGHT4);
glEnable(GL_LIGHT5);
glEnable(GL_LIGHT6);
glEnable(GL_DEPTH_TEST);
glEnable (GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
}

void display(void)
{

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);

GLfloat mat_specular[] = { 0.1, 0.1, 0.1, 0.1 };

GLfloat light_position0[] = { -4.5, -9.0, -16.0, 1.0 };
GLfloat light_position1[] = { -10.0, 1.0, 1.0, 0.0 };
GLfloat light_position2[] = { 0.4, 1.0, -1.0, 0.0 };
GLfloat light_position3[] = { 0.5, 0.5, -0.5, 0.5 };
GLfloat light_position4[] = { 0.5, 0.5, -0.5, 0.5 };
GLfloat light_position6[] = { 0.5, 0.5, -0.5, 0.5 };
GLfloat light_diffuse1[] = { 1.0, 0.4, 0.4, 1.0 };

GLfloat light_diffuse0[] = { 0.4, 1.0, 0.4, 1.0 };
GLfloat light_diffuse2[] = { 0.4, 0.4, 1.0, 1.0 };
GLfloat light_diffuse3[] = { 0.4, 0.4, 0.5, 0.5 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 30);
glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse2);
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
glLightfv(GL_LIGHT3, GL_POSITION, light_position3);
glLightfv(GL_LIGHT3, GL_DIFFUSE, light_diffuse3);
glLightfv(GL_LIGHT4, GL_POSITION, light_position0);
glLightf(GL_LIGHT4, GL_SPOT_CUTOFF, 30);
glLightfv(GL_LIGHT6, GL_POSITION, light_position6);
glLightfv(GL_LIGHT6, GL_SPECULAR, mat_specular);

GLfloat light5_position[] ={1.0, 1.0, 1.0, 0.0};
GLfloat light5_dir[] = {0, 0, 0, 1};
}

Zenja
03-15-2011, 07:33 AM
OpenGL will multiply the light position you specify with the current modelview matrix. Lighting calculations are then done in EYE coordinates, which may be different from what you're expecting. If you reposition the camera, after setting the light position, then you will have weird lighting effects.