Original Post
hi,
i use the following code from a Book to create a d3d device, but it fail to obtain the device could any suggest some potiential error in it:
// Initializes the Direct3D device
int InitDirect3DDevice( HWND hWndTarget, int Width, int Height, BOOL bWindowed,
D3DFORMAT FullScreenFormat, LPDIRECT3D8 pD3D,
LPDIRECT3DDEVICE8* ppDevice )
{
// Structure to hold information about the rendering method
D3DPRESENT_PARAMETERS d3dpp;
// Structure to hold information about the current display mode
D3DDISPLAYMODE d3ddm;
HRESULT r = 0;
if( *ppDevice )
(*ppDevice)->Release();
// Initialize the structure to 0
ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );
// Get the settings for the current display mode
r = pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
if( FAILED( r ) )
{
SetError( "Could not get display adapter information" );
return E_FAIL;
}
// The width of the back buffer in pixels
d3dpp.BackBufferWidth = Width;
// The height of the buffer in pixels
d3dpp.BackBufferHeight = Height;
// The format of the back buffer
d3dpp.BackBufferFormat = bWindowed ? d3ddm.Format : FullScreenFormat;
// The number of back buffers
d3dpp.BackBufferCount = 1;
// The type of multisampling
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
// The swap effect
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
// The handle to the window that we want to render to
d3dpp.hDeviceWindow = hWndTarget;
// Windowed or fullscreen
d3dpp.Windowed = bWindowed;
// Let Direct3D manage the depth buffer
d3dpp.EnableAutoDepthStencil = TRUE;
// Set the depth buffer format to 16 bits
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
// Use the default refresh rate available
d3dpp.FullScreen_RefreshRateInHz = 0;
// Present the information as fast as possible
d3dpp.FullScreen_PresentationInterval = bWindowed ? 0 : D3DPRESENT_INTERVAL_IMMEDIATE;
// Allow the back buffer to be accessed for 2D work
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
// Acquire a pointer to IDirect3DDevice8
r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, ppDevice );
if( FAILED( r ) )
{
SetError( "Could not create the render device" );
return E_FAIL;
}
// Save global copies of the device dimensions
g_DeviceHeight = Height;
g_DeviceWidth = Width;
// Save a copy of the pres params for use in device validation later
g_SavedPresParams = d3dpp;
return S_OK;
}