You can create a Direct3D viewport object by calling the IDirect3D::CreateViewport method. The following example demonstrates how to create an IDirect3DViewport interface. Then it demonstrates how to add the viewport to a device by calling the IDirect3DDevice::AddViewport method and how to set up the viewport by calling the IDirect3DViewport::SetViewport, IDirect3DViewport::SetBackground, and IDirect3DViewport::AddLight methods.
lpDirect3D->CreateViewport(
lplpDirect3DViewport, // Address of a new viewport
pUnkOuter); // NULL
lpD3DDevice->AddViewport(
lpD3DViewport) // Attach viewport to device
lpD3DViewport->SetViewport(
lpData); // Address of a D3DVIEWPORT structure that
// Sets the viewport's location on the screen
lpD3DViewport->SetBackground(
lphMat); // Address of a D3DMATERIALHANDLE for
// background
lpD3DViewport->AddLight(
lpD3DLight); // Address of a light object
Viewport objects reside on the interface and device lists. The object maintains a list of lights as well as screen data, and it may have a material handle and a texture handle for the background. You can use the IDirect3DViewport interface to get and set backgrounds and viewports, add and delete lights, and transform vertices.