Hi!
Well, D3D is definitely more complex than I thought it was!... I keep running into problem after problem. I hope things will calm down a bit once I have more experience...
Anyway, here goes... I have an application in which I display a rotating cube. I define my vertexes with the following format:
const DWORD VERTEX_FORMAT = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE;
My normals are all normalized and my diffuse color is set to blue (r:0, g:0, b:200). If I set lighting off with a call to SetRenderState( D3DRS_LIGHTING, FALSE ); I get a blue rotating cube with no shading, just the same uniform blue on every face of the cube. As far as I know, that is what I should be getting.
The problem comes from when I try to add a light to my scene. Here''s what I do:
m_pDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
m_pDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 128, 128, 128 ) );
D3DMATERIAL8 material;
ZeroMemory( &material, sizeof( material ) );
material.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
material.Ambient = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
m_pDevice->SetMaterial( &material );
D3DLIGHT8 light;
ZeroMemory( &light, sizeof( light ) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 0.0f );
light.Direction = D3DXVECTOR3( 0.0f, -1.0f, 0.0f );
m_pDevice->SetLight( 0, &light );
m_pDevice->LightEnable( 0, TRUE );
With the above code, my cube is gray instead of blue, but is otherwise identical to what I get with lighting turned off. I was expecting the different faces on my cube to at least be of different shades of gray. A face hit directly by the light should be brighter than one that is on the opposite side, right?
Am I missing anything here? Thanks for any advice!
Frederic FerlandStrategy First, Inc.http://www.strategyfirst.com