PDA

View Full Version : spotlight effect



fallout
10-10-2004, 06:59 AM
Hi, I'm trying to create a spotlight in my openGL program.

Basically its a cube world that goes from
X range = -50 , 50 {ie 100 units wide}
Y range = -20 , 20 {ie 40 units high}
Z range = 0, -100 {100 units deep}

I'm trying to get a spotlight to shine on the wall on the right side.

glEnable(GL_LIGHTING);

GLfloat dirVector0[]={ 1.0, 0.0, 0.0, 1.0};
GLfloat lightPos0[]={ 0.0, 0.0, -30.0, 1.0};
GLfloat ambientLight0[] = {2.2f, 2.2f, 2.2f, 1.0f};
GLfloat diffuseLight0[] = {1.0f, 1.0f, 1.0f, 1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);

glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 30.0);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dirVector0);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.5);

glEnable(GL_LIGHT0);

Now this gives unbelievable results:
I lights up the right side of the world, making the right wall the brightest. It looks nothing like a spotlight effect

If you change the 30.0 to anything below 25, you get no light at all.
And in the dirVector0, if you change it to anything other than the X axis, it doesn't work.

Anybody have any ideas?
Thanks

farshizzo
10-10-2004, 01:47 PM
Is your cube model highly tesselated? OpenGL lighting is done per-vertex, so you need a lot of polygons for it to look like a real spotlight.