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)
程式庫 D3D9.lib

另請參閱

IDirect3DDevice9

IDirect3DDevice9::GetLight

IDirect3DDevice9::GetLightEnable

IDirect3DDevice9::LightEnable