IDirect3DDevice9::SetLight 方法 (d3d9helper.h)

为此设备分配一组照明属性。

语法

HRESULT SetLight(
  [in] DWORD           Index,
  [in] const D3DLIGHT9 *unnamedParam2
);

参数

[in] Index

类型: DWORD

要设置的照明属性集的从零开始的索引。 如果此索引中存在一组照明属性,则 pLight 中指定的新属性会覆盖该属性。

[in] unnamedParam2

类型: const D3DLIGHT9*

指向 D3DLIGHT9 结构的指针,其中包含要设置的照明参数。

返回值

类型: HRESULT

如果该方法成功,则返回值D3D_OK。 如果方法失败,则可以D3DERR_INVALIDCALL返回值。

注解

通过准备 D3DLIGHT9 结构,然后调用 IDirect3DDevice9::SetLight 方法设置光线属性。 IDirect3DDevice9::SetLight 方法接受设备应将光线属性集置于其内部光线属性列表的索引,以及定义这些属性的已准备D3DLIGHT9结构的地址。 可以根据需要使用新信息调用 IDirect3DDevice9::SetLight ,以更新灯的照明属性。

每次使用从未分配过属性的索引调用 IDirect3DDevice9::SetLight 方法时,系统都会分配内存以适应一组照明属性。 应用程序可以设置多个灯,一次只启用一部分分配的灯光。 检索设备功能以确定该设备支持的最大活动光数时,请检查 D3DCAPS9 结构的 MaxActiveLights 成员。 如果不再需要灯,可以禁用它或使用一组新的光线属性覆盖它。

以下示例准备并设置白点光的属性,其发出的光不会随距离衰减。


// Assume d3dDevice is a valid pointer to an IDirect3DDevice9 interface.
D3DLIGHT9 d3dLight;
HRESULT   hr;
    
// Initialize the structure.
ZeroMemory(&d3dLight, sizeof(d3dLight));
    
// Set up a white point light.
d3dLight.Type = D3DLIGHT_POINT;
d3dLight.Diffuse.r  = 1.0f;
d3dLight.Diffuse.g  = 1.0f;
d3dLight.Diffuse.b  = 1.0f;
d3dLight.Ambient.r  = 1.0f;
d3dLight.Ambient.g  = 1.0f;
d3dLight.Ambient.b  = 1.0f;
d3dLight.Specular.r = 1.0f;
d3dLight.Specular.g = 1.0f;
d3dLight.Specular.b = 1.0f;
    
// Position it high in the scene and behind the user.
// Remember, these coordinates are in world space, so
// the user could be anywhere in world space, too. 
// For the purposes of this example, assume the user
// is at the origin of world space.
d3dLight.Position.x = 0.0f;
d3dLight.Position.y = 1000.0f;
d3dLight.Position.z = -100.0f;
    
// Don't attenuate.
d3dLight.Attenuation0 = 1.0f; 
d3dLight.Range        = 1000.0f;
    
// Set the property information for the first light.
hr = d3dDevice->SetLight(0, &d3dLight);
if (SUCCEEDED(hr))
    // Handle Success
else
    // Handle failure

通过为设备调用 IDirect3DDevice9::LightEnable 方法启用光源。

要求

要求
目标平台 Windows
标头 d3d9helper.h (包括 D3D9.h)
Library D3D9.lib

另请参阅

IDirect3DDevice9

IDirect3DDevice9::GetLight

IDirect3DDevice9::GetLightEnable

IDirect3DDevice9::LightEnable