Skip to main content
gamedev.net
🔒 Locked

Creating lights

Started by nicosio Mar 7, 2004 at 7:06 PM 0 replies 550+ views
Original Post
nicosio
nicosio
Hello: I can create a positional light that illuminate two spheres, the position of the light is shown by a wireframe sphere. using the following code: glLoadIdentity(); GLfloat posicion[]={x,y,z,1.0}; glLightfv(GL_LIGHT0,GL_POSITION,posicion); glEnable(GL_LIGHT0); glTranslatef(x,y,z); glutWireSphere(0.1,6,6); glLoadIdentity(); glTranslatef(-2.0f,0.0f,-5.0); glutSolidSphere(1.0,32.0,32.0); glLoadIdentity(); glTranslatef(2.0f,0.0f,-5.0); glutSolidSphere(1.0,32.0,32.0); Now my questions are, How do I modify it to be a directional light. For example a light that ilumminates from right to left. Let''s say that the light position will be at (10.0,0.0,-5.0) and it is pointing to (0.0,0.0,-5.0) And then how I tranform it to a spot light? with an apperture of 30 degrees? Does anyone knows of a good OpenGL light tutorial? I tried the one at Nehe, but didn''t got all the concepts. Thank you, Nicosio
Spockmeat
Spockmeat
when you specify the light position


GLfloat position[]={x,y,z,1.0};

change the last value to be a 0.0 and it will become directional instead of positional.

GLfloat position[] = {x,y,z,0.0f};

And then the x,y,z values become a vector indication the direction the light is pointin, so you may have to make them negative to get the effect you want. For example, if you have a point light at (2,2,2), and then you want a directional light shining from that point to the origin (will give you a very similar lighting at the origin as the original point light would have), the light would have to be pointing at (-2,-2,-2).

I'd have to look up how to do a spot light light again...



[edited by - Spockmeat on March 7, 2004 12:29:57 AM]
Black holes are where God divided by 0.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.