Change Lightsources position...?

Started by
6 comments, last by SnAkE 22 years, 9 months ago
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
Advertisement
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
quiet! don't disturb my sleep. i'm in office right now.
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
Precalculate your geometry surfaces normal coordinates and assign them with glNormal3x() - function per frame.
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...
You should never let your fears become the boundaries of your dreams.
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
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
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]--- -- -
- -- ---[XaOs]--- -- -[ Project fy ||| CyberTux ]

This topic is closed to new replies.

Advertisement