# Spot light (ie: street lamp)

## Recommended Posts

Brigs    122
What kind of settings do I need to make a light that would represent a street lamp for instance? I know that this type of light is SPOT_LIGHT and it needs to be EMISSION type?:
GLfloat materialEmission[] = {1.0f, 0.0f, 0.0f, 1.0};
GLfloat light_position[] = { 1.0, 1.0, 1.0, 1.0 };

glLightfv(GL_LIGHT1, GL_POSITION, light_position);

GLfloat spot_direction[] = { -1.0, -1.0, 0.0 };

glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); /* set the cutoff angle */

glLightfv(GL_LIGHT1, GL_EMISSION, materialEmission );

However I'm not seeing any red light in my scene. If I use a DIFFUSE light instead of EMISSION than I can see light but it is scattered around the scene, I want it to be in a certain spot and glow like a lamp. I'm also confused on how to set the size of the light so that it is intense only in a certain area, not scattered around the scene like ambient. thanks for any help!

##### Share on other sites
V-man    813
glLightfv(GL_LIGHT1, GL_EMISSION, materialEmission );
that shouldnt work. Call glGetError and you ll see GL returns an error code.

You need to use glMaterial(.., GL_EMISSION, ...)

##### Share on other sites
Brigs    122
Yes that worked! Only problem is the light is still all around my scene, how would I "attach" it to a specific object only?

##### Share on other sites
Thaumaturge    3824
Well, what do you mean by "all around [your] scene"? Do you mean that it's a directional light, or that you have a circle of light, but that it's too large?

Offhand, I note that you have your spotlight angle set to 45 degrees, which seems to me to be a little large - perhaps try lowering that.

Other than that, perhaps it would help to set the spotlight exponent (GL_SPOT_EXPONENT, I believe) along with the direction and cut-off angle.

As to "attaching" it, I think that that just comes down to moving it to the appropriate position relative to the object.

##### Share on other sites
nemesisgeek    139
Emissive materials are in no way associated with lighting. They do not actually "emit" light - they simply make the object LOOK like it is glowing.

To simulate a glowing object, you need to have two things:
* A light (using diffuse and specular terms as appropriate)
* The object itself

##### Share on other sites
Brigs    122
Here are some screen shots: As you can see the wall is shining towards the wall, but getting spread across the whole wall, while what I need it to do is concentrate in one small circle of light, as if it was a search light...

[img]http://img296.imageshack.us/img296/3884/spot1sq6.jpg[/img]

[img]http://img387.imageshack.us/img387/4375/spot2cz0.jpg[/img]

GLfloat materialEmission[] = {1.0f, 0.0f, 0.0f, 1.0};GLfloat light_position[] = {1.0, 1.0, 1.0, 1.0};glLightfv(GL_LIGHT1, GL_POSITION, light_position); GLfloat spot_direction[] = { 1, 0, 0 }; /* direction of light along the x axis (towards the wall)glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction);glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); /* set the cutoff angle */glLightfv(GL_LIGHT1, GL_DIFFUSE, materialEmission);`

I am able to move the light around and move it closer to the wall, but it does not affect the spread :(

##### Share on other sites
OrangyTang    1298
Regular fixed function lighting is only per-vertex, and interpolated across the surface of polys. I'd guess your walls are only made from a couple of triangles so you won't get a nice focused effect like you're after. Either tessalate your wall more or switch to a per-pixel approach via shaders.