For some reason, when I try to use lighting, my triangle doesn't show up on the screen, just a blank screen really.
What I thought it might be is that I'm normalizing the vertices wrong. I'm simply using D3DXVec3Normalize() to do this for me, as shown:
D3DXVec3Normalize((D3DXVECTOR3*)&Triangle[0].normal, &Triangle[0].pos);
D3DXVec3Normalize((D3DXVECTOR3*)&Triangle[1].normal, &Triangle[1].pos);
D3DXVec3Normalize((D3DXVECTOR3*)&Triangle[2].normal, &Triangle[2].pos);
(I use those functions later in the program, after I've already defined the vertices...)
Note that my vertices are defined as follows:
struct DGVERTEXNORM
{
D3DXVECTOR3 pos; // xyz coords
D3DXVECTOR3 normal; // normal for lighting
DWORD dwColor; // color
};
DGVERTEXNORM Triangle[] =
{
{ D3DXVECTOR3(-1.0f, -1.0f, 5.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DCOLOR_XRGB(255, 0, 0) },
{ D3DXVECTOR3(-1.0f, 1.0f, 5.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DCOLOR_XRGB(0, 255, 0) },
{ D3DXVECTOR3(1.0f, -1.0f, 5.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DCOLOR_XRGB(0, 0, 255) }
};
Here's the code I use to set the light and the material (before the main loop starts):
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_POINT;
light.Position = D3DXVECTOR3(0.0f, 0.0f, 3.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;
graphics.EnableLighting();
graphics.GetDevice()->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
graphics.GetDevice()->SetLight(0, &light);
graphics.GetDevice()->LightEnable(0, TRUE);
D3DMATERIAL9 material;
material.Diffuse.r = material.Diffuse.g = material.Diffuse.b = material.Diffuse.a = 1.0f;
material.Ambient.r = material.Ambient.g = material.Ambient.b = material.Ambient.a = 1.0f;
graphics.GetDevice()->SetMaterial(&material);
(graphics.EnableLighting() is the same as graphics.GetDevice()->SetRenderState(D3DRS_LIGHTING, TRUE))
Yes, my projection/view matrices are setup right and the triangle is being displayed properly otherwise (I know this because whenever I comment out the lighting code and disable lighting, it shows up fine).
[Edited by - dist0rted on July 26, 2007 1:13:24 PM]
=============================All knowledge is good; only the way it is put to use is good or evil.