The following illustration shows a common creation path of a light in Direct3D.
You create a light object by calling the IDirect3D3::CreateLight method. The first parameter is the address of a variable that will contain a valid IDirect3DLight interface pointer if the call succeeds. The method's second parameter is intended to be used in COM aggregation — because aggregation is not implemented, this parameter must be set to NULL. The following example shows what the code to make this call might look like:
/*
* For the purposes of this example, the g_lpD3D3 variable is the
* address of an IDirect3D3 interface exposed by a Direct3D
* object.
*/
LPDIRECT3DLIGHT g_lpD3DLight;
HRESULT hr;
hr = g_lpD3D3->CreateLight (&g_lpD3DLight, NULL);
if (SUCCEEDED(hr))
{
// Set the light properties.
}
else
return hr;
Before you can use the light object, you must set its properties. For more information, see Setting Light Properties.