Archived

This topic is now archived and is closed to further replies.

SnAkE

Change Lightsources position...?

Recommended Posts

Hi there, I decided to use lighting for the first time, but now there is something, that I do not understand: OK, read NeHe''s tutorial on lighting, and it works quite allright, but what to do if I want the Lightsource to be part of the "world", and not of the camera?! (Get that?) In the tutorial the Light is static, so you can not move it around, and what do I have to do, to make it moveable??? Thanx, SnAkE SnAkE''s Programming Resources

Share this post


Link to post
Share on other sites
just use

glLightfv( GL_LIGHT0, GL_POSITION, posLight0 );

with

float posLight[4]; // x, y, z, w


of course GL_LIGHT0 is exchangeable with GL_LIGHT1 ...


hope this helps
Johann Fuchs

Share this post


Link to post
Share on other sites
Got some code:

in the InitGL-Function, I wrote the following:
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

And if I run it now, everything works fine... but the lightsource is always at a fixed position, compared to the camera.
Now I test something like that in the DrawGl-Function:
LightPosition[0]=   0.0f-move_x;
LightPosition[1]= -5.0f-move_y;
LightPosition[2]= -25.0f-move_z;
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);

With this code added, the scene is completely black...

Question: What do I have to do, to make the light work?


SnAkE''s Programming Resources

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Precalculate your geometry surfaces normal coordinates and assign them with glNormal3x() - function per frame.

Share this post


Link to post
Share on other sites
I''m also having problems with this...

I have something like:
LightPosition[0]= light1.z;
LightPosition[1]= light1.y;
LightPosition[2]= light1.z;
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);

but NOTHING happens when I move the light...
and I have normals(actualy i reied both per vertic and per face) and nothing seems to work...

There are more worlds than the one that you hold in your hand...

Share this post


Link to post
Share on other sites
check the faq (lighting section question 5 IIRC)
http://www.frii.com/~martz/oglfaq/
asfter u move the camera u must position the lights again.

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Make sure the fourth component in the light vector is a 1.0 if you want to move the light around. Like i said in your other post and like it says in the NeHe tutorial, the 1.0 tells opengl the vector you specify is the light position. If its a 0.0 then the light is an infinate distance away and the vector you choose is the direction of the light only.

-SirKnight

Share this post


Link to post
Share on other sites
I had the same problem once but i solved it
by setting up the lights before i translated
the world coord! (Got that one?)



I got some source for you snake if you are
interested!!



I''ll send it to you if you wan''t it!!



and btw...the music stuff was harder the expected!!




Take Care!


- -- ---[XaOs]--- -- -

Share this post


Link to post
Share on other sites