DirectX 9 Light
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?
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.
Post the code where you set up the D3DLIGHT9 structure as well.
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 ?
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 ?
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]
[Edited by - IndyJones on March 4, 2007 12:49:21 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement