?/TD> |
Microsoft DirectX 9.0 |
To create a Direct3D device in a C++ application, your application must first create a Direct3D object, as explained in Direct3D Object.
First, initialize values for the D3DPRESENT_PARAMETERS structure that is used to create the Direct3D device. The following code example specifies a windowed application where the back buffer is flipped to the front buffer on VSYNC only.
LPDIRECT3DDEVICE9 pDevice = NULL; D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
Next, create the Direct3D device. The following IDirect3D9::CreateDevice call specifies the default adapter, a hardware abstraction layer (HAL) device, and software vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice ) ) ) return E_FAIL;
Note that a call to create, release, or reset the device should happen only on the same thread as the window procedure of the focus window.
After creating the device, set its state.