Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting types

Started by Cybertron Aug 8, 2002 at 4:47 PM 3 replies 700+ views
Original Post
Cybertron
Cybertron
Let me ask this again: In d3d there are 3 types of lights: directional, point and sporlight. How do I make this distinction in OpenGL?
Cybertron
Cybertron
Thanks for your response. I know that set of functions sets the light''s paramiter, but how do tell it what type of light to render? Do I just not specify the paramiters that don''t apply to the light?
benjamin bunny
benjamin bunny
quote:
Original post by Cybertron
Thanks for your response. I know that set of functions sets the light's paramiter, but how do tell it what type of light to render? Do I just not specify the paramiters that don't apply to the light?


The default values are indicated in the glLight entry in MSDN. Obviously you only need to set parameters where your desired value differs from the default value (or the previous value, if it's already set).

Here's an example of setting up GL_LIGHT0 as a positional spotlight:

      
float dir[4]{0,1,0,0}; //direction normal (straight up)

float lightPos[4]{5,20,10,1}; //light position (last element being a 1 specifies a positional light - see MSDN)

glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir); //specify direction

glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 8); //smooth distribution

glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45); //45 degrees

glLightfv(GL_LIGHT0, GL_POSITION, pos); //specify position

glEnable(GL_LIGHT0); //enable the light



Then, every frame, at the top of your render code, after the modelview matrix has been transformed for your camera, specify the position again. This makes sure that the light position is transformed by the modelview matrix for your current camera position.

  
glLightfv(GL_LIGHT0, GL_POSITION, pos);

//draw stuff



____________________________________________________________
www.elf-stone.com


[edited by - benjamin bunny on August 8, 2002 9:50:23 PM]

Topic Locked

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

Sign in to reply to this topic.