Sign in to follow this  
Brigs

Spot light (ie: street lamp)

Recommended Posts

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 this post


Link to post
Share on other sites
glLightfv(GL_LIGHT1, GL_EMISSION, materialEmission );
that shouldn`t work. Call glGetError and you ll see GL returns an error code.

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

Share this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this