Sign in to follow this  
xM1k3x

Spotlights, DirectX lighting woes

Recommended Posts

Hey all I'm having trouble getting the directx lighting to work in my program. Its the spotlight, and I dont see it I cant see any light. If I switch it to point light I see the light immediately so I cant tell whats wrong. Here is the code for the light:
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = 1.0f;

// Set default rendering states.
g_D3DDevice->SetRenderState(D3DRS_LIGHTI... TRUE);
g_D3DDevice->SetRenderState(D3DRS_AMBIEN...
D3DCOLOR_COLORVALUE(0.3f, 0.3f, 0.3f, 1.0f));

// Setup the light source.
g_light.Type = D3DLIGHT_SPOT;
g_light.Direction = D3DXVECTOR3(-0.0f, -0.0f, 0.0f);
g_light.Diffuse.r = 1.0f;
g_light.Diffuse.g = 1.0f;
g_light.Diffuse.b = 1.0f;
g_light.Diffuse.a = 1.0f;
// g_light.Specular.r = g_light.Specular.g = 1;
//g_light.Specular.b = g_light.Specular.a = 1;

g_light.Position = pos;

g_light.Range = 1.0f;
g_light.Theta = 0.0f;
g_light.Phi = 0.0f;
g_light.Falloff = 1.0f;
g_light.Attenuation0 = 1.0f;
g_light.Attenuation1 = 1.0f;
g_light.Attenuation2 = 1.0f;

// Register the light.
g_D3DDevice->SetLight(0, &g_light);
g_D3DDevice->LightEnable(0, TRUE);

// Setup the material properties for the teapot.
ZeroMemory(&g_material, sizeof(D3DMATERIAL9));
g_material.Diffuse.r = g_material.Ambient.r = 0.6f;
g_material.Diffuse.g = g_material.Ambient.g = 0.6f;
g_material.Diffuse.b = g_material.Ambient.b = 0.7f;
g_material.Specular.r = 0.4f;
g_material.Specular.g = 0.4f;
g_material.Specular.b = 0.4f;
g_material.Power = 8.0f;

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
Try this:


g_light.Range = 1000.0f;
g_light.Phi = D3DX_PI;
g_light.Theta = D3DX_PI / 2;


See the SDK for more info on what these members stand for.


I did what you said but I still cant see the light. Maybe its the color that the light is im not sure how to change the color so maybe if I made it, lets say red then I would be able to see it?

Can someone tell me what variable controls the lights color?

Share this post


Link to post
Share on other sites
I didn't spot it the first time, but you're setting the light's direction to be the zero vector, which is not allowed (and doesn't make sense if you think about it).

This is another thing that is listed in the SDK.

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