Platform SDK: DirectX

Using Direct3DX to Initialize Direct3D and DirectDraw

The Direct3DX utility library provides initialization support for Direct3D and DirectDraw.

Direct3D is implemented through COM objects and interfaces. The Direct3D interfaces are interfaces to the DirectDraw object which represents the display device. Direct3DX creates the DirectDraw object and the Direct3DDevice object for your application in a single step by creating a context object.

    if(FAILED(hr = D3DXCreateContextEx(D3DX_DEFAULT, 0, g_hwnd, NULL, D3DX_DEFAULT, 0,
        D3DX_DEFAULT, 0, 1, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, &g_pd3dx)))
    {
        return hr;
    }

As the code sample shows, the D3DXCreateContextEx function will return the address of a pointer to an ID3DXContext interface. Note that the D3DXCreateContext function will also return the address of a pointer to an ID3DXContext interface. See the reference pages for the differences between the D3DXCreateContext and D3DXCreateContextEx functions.

For information on contexts and how contexts wrap Direct3D and DirectDraw objects, see Direct3DX Context.

Direct3DX provides another useful, time-saving initialization feature: a mechanism to enumerate the capabilities of the various devices in the system. For information on devices and device enumeration specific to Direct3DX, see Direct3DX Devices.