Jump to content
  • Advertisement
Sign in to follow this  
Mari_p

Simple doubt about more than one light in the scene

This topic is 4569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I would to add more than one light in my scene, but I am a bit confused on how to proceed... Suppose, for example, that I want to add 3 lights in my scene. Would it be wrong call the following function 3 times?
// Just an exemple...
VOID Lighting( "pass the device, light's position, light's range etc..." )
{
   D3DLIGHT9 light;
   ZeroMemory(&light, sizeof(light));

   light.Type = ...;
   light.Diffuse.r  = ...;
   light.Diffuse.g  = ...;
   light.Diffuse.b  = ...;
   light.Ambient.r  = ...;
   light.Ambient.g  = ...;
   light.Ambient.b  = ...;
   light.Specular.r = ...;
   light.Specular.g = ...;

   light.Specular.b = ...;
   light.Position.x = ...;
   light.Position.y = ...;
   light.Position.z = ...;

   light.Attenuation0 = ...;
   light.Range        = ...;

   pDevice->SetLight(0, &light);
   pDevice->LightEnable(0, TRUE);
}
Do I need to change the index values in SetLight and LightEnable methods, for each light? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
The first parameter of SetLight and LightEnable specifies which light. If you leave the parameter at 0, then you are only affecting one light -- light 0. If you want 3 lights then you have to specify 3 different lights, (e.g. 0, 1, and 2).

Share this post


Link to post
Share on other sites
Quote:

Would it be wrong call the following function 3 times?

Nope, not at all.. but there are easier ways to not have to duplicate code.
You could create methods that will create a light for you and place it in a collection.
What I normally do is have an array of lights and this is how I managed individual lights in the fixed function pipeline.
Then for each light you will set it to the device.
e.g.
IDirect3DDevice9::SetLight(lightNumber, &light[lightNumber]);

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!