Skip to main content
gamedev.net
🔒 Locked

createDevice

Started by CYM_AhYan 2 replies 300+ views
Original Post
CYM_AhYan
CYM_AhYan
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; }
Rookie on game dev.
Lifepower
Lifepower
I don''t see anything wrong with the code, however you''d check if the format of your back and stencil buffers are supported by the used device (try getting D3DCAPS8 structure from IDirect3D8::GetDeviceCaps). Also check if you''re passing expected values to back buffer format. If all parameters are ok, then perhaps there''s some minor mistakes in the code which prevent Direct3D to initialize.

Sorry for I can''t tell you more...
- Lifepower
Anozireth
Anozireth
I know this is really basic, but I''d also suggest making sure your video card can handle what you are trying to do.
Kooo
Kooo
I haven''t used Direct3D at all (just DirectDraw) so I can''t really help by looking at your code.

But, have you tried installing the debug runtime version of DirectX? It display error messages
(in a VC++ window) indicating why the failure occurred.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.