sucking spotlights!

Started by
8 comments, last by Gammastrahler 22 years, 2 months ago
i have trouble with opengl spotlights. i have read many tutorials about it, i copied code examples, but they don´t work!
    
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

GLfloat spotdir[3] = {0, -1, 0};
GLfloat pos[4] = {0, 100, 0, 1.0};

glLightfv(GL_LIGHT0, GL_POSITION, pos);

glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotdir);

glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20);
    
i have tried dozens of different values for the cutoff angle and spot exponent, but nothing changed. anyone an idea? Edited by - gammastrahler on February 6, 2002 2:31:33 PM
Advertisement
I''m not sure that spotdir[3] = {0, -1, 0}; is a good value...
Try that spotdir[3] = {0, -1, -10};
no, the spot dir is a unit vector and needs in the range -1..1

i´m wondering about i tried about 50 different cutoff and exponent values but the light cone never changes....

what the hell is going on?
You are shining the light cone onto a vertex. Lighting in OpenGl is done at the vertices - so if your spotlight cone doesn''t intersect any vertices they it''ll look like no light is on.

Chris
really stupid question (not trying to insult you), but is your geometry tesselated enough to show these changes?

it may just be that there aren''t enough vertices to accurately show the different cut-offs... but then, you would expect a big difference between something like 5 degrees and 45 degrees wouldn''t you??
i actually use simple geometry (quads for walls, etc).

i´m wondering how lighting is done in unreal (rooms are also build from simple quads).
quote:Original post by Gammastrahler
i actually use simple geometry (quads for walls, etc).
That''s why your spotlight won''t show up. Check out item 2 in this article.
quote:Original post by Gammastrahler
i´m wondering how lighting is done in unreal (rooms are also build from simple quads).
Lightmapping. That''s really the best way to handle spotlights.
In Unreal, they take a huge triangle and tesselate into a load of really small triangles. This way, there are loads of vertices to perform lighting calculations on, and you get a nice spotlighted surface.

Don''t worry. This got me for a while. Try and write some algorithms that tesselate large triangles into smaller ones...

iNsAn1tY - the place where imagination and the real world merge...
Try http://uk.geocities.com/mentalmantle - Now updated!
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
thanks for the replies! but high tesselation means performance cuts... i think dynamic lightmapping would be the choice for me. does anyone know about good tutorials about this?

thanks gammastrahler
Theres an example with source here.

And there is a tutorial here.

"To err is human, to really mess up requires a computer"

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. "
- Albert Einstein


Edited by - Lukerd on February 7, 2002 4:54:13 AM
"To err is human, to really mess up requires a computer"

This topic is closed to new replies.

Advertisement