Sign in to follow this  

DirectX 9 Light

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
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->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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this