PDA

View Full Version : Fixed light and moving spot light with the mouse



Jorcelangelo
04-18-2012, 08:56 PM
I need to understand how to place a fixed light in on location and one spot light moving with the move.

The following code is my attempt:

void myinit() {
float mat_specular[]={0,0.5,1,1};
float mat_shininess[]={10};
float light_position[]={1,1,1,0};
float purple_light[]={.5,.0,0.0,0};
GLfloat direction[] = { -1.0, -1.0, 0.0 };
GLfloat spot_direction[] = { ox, oy, oz };
glClearColor(0,0,0,0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, purple_light);

glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction);

gluLookAt(0,0,0, ox, oy, oz, 0,1,0);
glLightfv(GL_LIGHT1, GL_POSITION, spot_direction);
glLightfv(GL_SPOT_DIRECTION,GL_SPOT_CUTOFF, direction);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);

// Begin with an identity matrix.
glLoadIdentity();

// gluPerspective() and gluLookAt() modify the contents of the GL_PROJECTION matrix.
// Total field of view is 50 degrees, aspect ratio is 1.5 (width/height).
// Front clip plane at 1.0 and rear clip plane at 100.0.
gluPerspective(50.0, 1.5, 1.0, 100.0);

// Subsequent transformations will be to the model view matrix.
glMatrixMode(GL_MODELVIEW);

// Sky blue background color.
glClearColor(0.20, 0.6, 0.7, 0.00);

// Use Z-Buffer hidden-surface removal.
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);

}

The fixed light is working fine on my object, (well, fine it is at lease on my understanding). However, the spot light is not working. What do I need to change or add to this code to get the spot light working and moving with the mouse?

I appreciate any help.
Thank you!