DirectX SDK

D3DXCreateContext

The D3DXCreateContext function initializes the specified device.

HRESULT D3DXCreateContext(
  DWORD deviceIndex,
  DWORD flags,
  HWND hwnd,
  DWORD width,
  DWORD height,
  LPD3DXCONTEXT* ppCtx
); 

Parameters

deviceIndex
An index value specifying the device. Specifying D3DX_DEFAULT for this parameter will initialize the device with the highest acceleration level afforded on the primary surface. For a complete list of possible values see the Hardware Acceleration Level Constants reference topic.
flags
The valid flags are D3DX_CONTEXT_FULLSCREEN, and D3DX_CONTEXT_OFFSCREEN. These flags cannot both be specified. If no flags are specified, the context defaults to windowed mode.
hwnd
The device window. See remarks.
width
The width of the window, in pixels, or D3DX_DEFAULT. See remarks.
height
The height of the window, in pixels, or D3DX_DEFAULT. See remarks.
ppCtx
The address of a pointer to the context object that is used for rendering on the chosen device.

Return Values

If the function succeeds, the return value is S_OK.

If the function fails, the return value may be one of the following values:

D3DXERR_D3DXNOTSTARTEDYET
D3DXERR_INITFAILED
D3DXERR_INVALIDPARAMETER
D3DXERR_NOMEMORY
D3DXERR_NOZBUFFER
D3DXERR_NOZBUFFERAVAILABLE
D3DXERR_NULLPOINTER
DDERR_CANNOTATTACHSURFACE
DDERR_GENERIC
DDERR_INCOMPATIBLEPRIMARY
DDERR_INVALIDCAPS
DDERR_INVALIDOBJECT
DDERR_INVALIDPARAMS
DDERR_INVALIDPIXELFORMAT
DDERR_INVALIDSURFACETYPE
DDERR_NOALPHAHW
DDERR_NOCLIPPERATTACHED
DDERR_NOCOOPERATIVELEVELSET
DDERR_NODIRECTDRAWHW
DDERR_NOEMULATION
DDERR_NOEXCLUSIVEMODE
DDERR_NOFLIPHW
DDERR_NOMIPMAPHW
DDERR_NOOVERLAYHW
DDERR_NOPALETTEATTACHED
DDERR_NOPALETTEHW
DDERR_NOT8BITCOLOR
DDERR_NOZBUFFERHW
DDERR_OUTOFMEMORY
DDERR_OUTOFVIDEOMEMORY
DDERR_PRIMARYSURFACEALREADYEXISTS
DDERR_SURFACEALREADYATTACHED
DDERR_SURFACELOST
DDERR_UNSUPPORTED
DDERR_UNSUPPORTEDMODE
DDERR_WASSTILLDRAWING

Remarks

If your application is operating in windowed mode, hwnd must be a valid window (it cannot be NULL or D3DX_DEFAULT). Also, if either width or height is D3DX_DEFAULT, both values default to the dimensions of the client area of hwnd.

If your application is operating in full-screen mode, hwnd must be a valid window (it cannot be NULL or D3DX_DEFAULT). Also, if either width or height is D3DX_DEFAULT, width defaults to 640 pixels, and height defaults to 480 pixels.

If your application is operating in off-screen mode: hwnd must be NULL or D3DX_DEFAULT. An error is returned if either width or height is D3DX_DEFAULT.

The D3DXCreateContext function is the simplest Direct3DX initialization function available. Parameters are treated the same as the matching subset of parameters in the D3DXCreateContextEx function. The D3DXCreateContextEx parameters not present in the D3DXCreateContext function are treated as D3DX_DEFAULT.

Note  Multiple monitor systems are not supported by contexts created with the D3DXCreateContext function. For multiple monitor support, see the D3DXCreateContextEx function.

As with any function, you should not expect D3DXCreateContext to be fail-safe. Supported device capabilities should be used as a guide for choosing parameter values. Inevitably, there will be some combinations of parameters that do not work.

The default projection matrix setup by the D3DXCreateContext function is a left-handed perspective projection with a field-of-view (fov) of pi/2 radians.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Windows CE: Unsupported.
  Version: Requires DirectX 7.0.
  Header: Declared in d3dxcore.h.
  Library: Use d3dx.lib.

See Also

D3DXCreateContextEx