spotlight effect

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

  1. make sure, your modelviewmatrix is identity when you specifiy the lightposition.
  2. try using a pointlight instead of a directional lightsource.(use attenuation to arcieve this)
  3. read this:
    http://www.opengl.org/resources/faq/technical/index.html#indx0180

Your “cube world” must be tesselated at a sufficient level for the spotlight to be visible. I would guess that your “walls” are made of a single quad (or two triangles). The standard lighting in Opengl is calculated per Vertex. If your spotlight doesn’t immediately shine on a vertex then you won’t see any significant lighting (which is what I suspect is happening when you reduce the cone angle).

No doubt it says that in the FAQ you have been pointed to.

Thanks rgpc,
Your right, I had one big quad for the walls.
Once I made a wall from a bunch of smaller polygons, it worked great.
Thanks