PDA

View Full Version : spot light question



03-29-2004, 10:47 PM
I've been trying to work this code from the red book on a cube..
but I cant seem to see any spotlight happening..
can someone help me please! thank you

///
GLfloat light1_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat light1_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light1_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light1_position[] = { -2.0, 2.0, 1.0, 1.0 };
GLfloat spot_direction[] = { -1.0, -1.0, 0.0 };

glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5);
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);

glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0);
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);

glEnable(GL_LIGHT1);

///

Bob
03-30-2004, 02:11 AM
I see you enable the light itself, but not the lighting system.

glEnable(GL_LIGHTING);

eror
03-30-2004, 05:09 AM
When you use lights, you only change the color of vertices, not polygon (color of polygon is interpolated {or not} color of vertices). You will never see spot-light on polygon that has too little vertices. Maybe that is your problem. If not, surely the answer above is helpful.

roffe
03-30-2004, 11:14 AM
Please see issue 2 in this guide from the front page:

Pitfalls (http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/)

eror
03-30-2004, 11:27 AM
Roffe came with ultimate aswer to all basic questions :) - doc about avoiding pitfalls. Read it all- section mentioned by Roffe is that what I wrote above, but written in better english :) .