Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
You set lighting properties in a C++ application by preparing a D3DMLIGHTstructure and then calling the IDirect3DMobileDevice::SetLightmethod. The SetLightmethod accepts the index at which the device should place the set of light properties to its internal list of light properties, and the address of a prepared D3DMLIGHTstructure that defines those properties. You can call SetLightwith new information as needed to update the light's illumination properties.
The system allocates memory to accommodate a set of lighting properties each time you call the SetLightmethod with an index that has never been assigned properties. Applications can set a number of lights, with only a subset of the assigned lights enabled at a time. Check the MaxActiveLightsmember of the D3DMCAPSstructure when you retrieve device capabilities to determine the maximum number of active lights supported by that device. If you no longer need a light, you can disable it or overwrite it with a new set of light properties.
The following C++ code example prepares and sets properties for a white point-light whose emitted light will not attenuate over distance.
Copy Code | |
---|---|
/* * For the purposes of this example, the d3dmDevice variable * is a valid pointer to an IDirect3DMobileDevice interface. */ D3DMLIGHT d3dmLight; HRESULT hr; // Initialize the structure. ZeroMemory(&d3dmLight, sizeof(D3DMLIGHT)); // Set up a white point light. d3dmLight.Type = D3DLIGHT_POINT; d3dmLight.Diffuse.r = 1.0f; d3dmLight.Diffuse.g = 1.0f; d3dmLight.Diffuse.b = 1.0f; d3dmLight.Ambient.r = 1.0f; d3dmLight.Ambient.g = 1.0f; d3dmLight.Ambient.b = 1.0f; d3dmLight.Specular.r = 1.0f; d3dmLight.Specular.g = 1.0f; d3dmLight.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. d3dmLight.Position.x = 0.0f; d3dmLight.Position.y = 1000.0f; d3dmLight.Position.z = -100.0f; // Do not attenuate. d3dmLight.Attenuation0 = 1.0f; d3dmLight.Range = 1000.0f; // Set the property information for the first light. hr = d3dmDevice->SetLight(0, &d3dmLight); if (FAILED(hr)) { // Code to handle the error goes here. } |
You can update a set of light properties with another call to SetLightat any time. Just specify the index of the set of light properties to update and the address of the D3DMLIGHTstructure that contains the new properties.
Note: |
---|
Assigning a set of light properties to the device does not enable the light source whose properties are being added. Enable a light source by calling the IDirect3DMobileDevice::LightEnablemethod for the device. |