Public Group

# Spotlights, DirectX lighting woes

This topic is 3653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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.

##### Share on other sites
Quote:
 Original post by Gage64Try 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 on other sites
Anyone please? There seems to be no good articles on spotlights so this is my one place for help. I appreciate any insight.

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

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 18
• ### Forum Statistics

• Total Topics
632160
• Total Posts
3004500

×