• Advertisement
Sign in to follow this  

DirectX 9 Light

This topic is 3976 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

Hy! I am trying to use some light on an object, but unfortunately it doesn't seem to work. I tried different techniques but still it doesn't appear. I am trying the simple type D3DLIGHT_POINT. Can anyone give me some advice?

Share this post


Link to post
Share on other sites
Advertisement
As well as calling Device->SetLight(0,&Light), are you calling Device->LightEnable(0,TRUE)?

Post the code where you set up the D3DLIGHT9 structure as well.

Share this post


Link to post
Share on other sites
I think I have figured out something, but I have to ask you to be sure.
Yes, I used those two functions correctly (from what I saw in the DirectX sample), but I think I placed the code in the wrong place, I mean the Initialization function.
Take a look at the code:

D3DLIGHT9 Light;
ZeroMemory(&Light, sizeof(D3DLIGHT9));

Light.Type = D3DLIGHT_POINT;

Light.Position.x = -50.0f;
Light.Position.y = 50.0f;
Light.Position.z = -100.0f;

Light.Diffuse.a = Light.Ambient.a = 1.0f;
Light.Diffuse.r = Light.Ambient.r = 1.0f;
Light.Diffuse.g = Light.Ambient.g = 1.0f;
Light.Diffuse.b = Light.Ambient.b = 1.0f;
Light.Range = 1000.0f;
g_pD3DDevice->SetLight(0,&Light);
g_pD3DDevice->LightEnable(0, TRUE);

g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
g_pD3DDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );

Now this code is in a function which is called in the DoFrame() function, and apparently this works fine.

So my question is do I have to call it always in the DoFrame() where all the per-frame operations are done, or I can call it also in the initialization but with some minor modifications ?

Share this post


Link to post
Share on other sites
Are you using materials (D3DMATERIAL9) as well? Without defining materials (via SetMaterial) lighting doesn't work with the FF pipeline.

[Edited by - IndyJones on March 4, 2007 12:49:21 PM]

Share this post


Link to post
Share on other sites
I tried using material and it worked fine. Now I am using textures. It seems that I have no problem with combining light and texture, and I found some great effects that I can apply like setting some colors on texture. It really gets interesting!

Share this post


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

  • Advertisement