To use the DrawPrimitive methods, your application must first initialize the DirectDraw object in the normal manner and obtain a pointer to the IDirect3D3 interface. For details, see Retrieving an IDirect3D3 Interface. It must then call the IDirect3D3::CreateDevice method to create a Direct3D device. This method will pass a pointer to the IDirect3DDevice3 interface your application.
The following figure illustrates the process for creating a Direct3D device that supports the DrawPrimitive methods.
This code fragment illustrates this process:
LPDIRECTDRAW lpDD; // DirectDraw Interface
LPDIRECT3D3 lpD3D; // Direct3D3 Interface
LPDIRECTDRAWSURFACE4 lpddsRender; // Rendering surface
LPDIRECT3DDEVICE3 lpd3dDevice; // D3D Device
// Create DirectDraw interface.
// Use the current display driver.
hResult = DirectDrawCreate (NULL, &lpDD, NULL);
if (FAILED (hResult))
{
// Code to handle the error goes here.
}
// Get an IDirect3D3 interface
hResult =
lpDD->QueryInterface (IID_IDirect3D3, (void **)&lpD3D);
if (FAILED (hResult))
{
// Code to handle the error goes here.
}
//
// Code for the following tasks is omitted for clarity.
//
// Applications will need to set the cooperative level at this point.
// Full-screen applications will probably need to set the display
// mode.
// The primary surface should be created here.
// The rendering surface must be created at this point. It is
// assumed in this code fragment that, once created, the rendering
// surface is pointed to by the variable lpddsRender.
// If a z-buffer is being used, it should be created here.
// Direct3D device enumeration can be done at this point.
hResult = lpD3D->CreateDevice (IID_IDirect3DHALDevice,
lpddsRender,
&lpd3dDevice,
NULL);
The preceding sample invokes the IDirect3D3::CreateDevice method to create the Direct3D device. In the case of this sample, a Direct3D HAL device is created if the call is successful.
Note that the target DirectDraw rendering surface that your application creates must be created for use as a Direct3D rendering target. To do this, it must pass a DDSURFACEDESC2 structure to the IDirectDraw4::CreateSurface method. The DDSURFACEDESC2 structure has a member called ddsCaps, which is a structure of type DDSCAPS. The DDSCAPS structure contains a member named dwCaps, which must be set to DDSCAPS_3DDEVICE when IDirectDraw4::CreateSurface is invoked.
The render target surface you use must be created in display memory (with the DDSCAPS_VIDEOMEMORY flag) when it will be use with a hardware-accelerated rendering device, and in system memory (using the DDSCAPS_SYSTEMMEMORY flag) otherwise.