Direct3D CreateDevice

This is a discussion on Direct3D CreateDevice within the Game Programming forums, part of the General Programming Boards category; Code: pDirect3D=Direct3DCreate9(D3D_SDK_VERSION); if(pDirect3D==NULL) { goto EXIT; } D3DPRESENT_PARAMETERS D3DPresentParams; ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS)); D3DPresentParams.Windowed=false; D3DPresentParams.BackBufferCount=1; D3DPresentParams.BackBufferWidth=800; D3DPresentParams.BackBufferHeight=600; D3DPresentParams.BackBufferFormat=D3DFMT_X8R8G8B8; D3DPresentParams.SwapEffect=D3DSWAPEFFECT_DISCARD; D3DPresentParams.hDeviceWindow=hWnd; HRESULT hResult ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    27

    Direct3D CreateDevice

    Code:
    pDirect3D=Direct3DCreate9(D3D_SDK_VERSION);
    		if(pDirect3D==NULL)
    			{
    			
    			goto EXIT;
    			}
    	D3DPRESENT_PARAMETERS D3DPresentParams;
    	
    ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS));
    		D3DPresentParams.Windowed=false;
    		D3DPresentParams.BackBufferCount=1;
    		D3DPresentParams.BackBufferWidth=800;
    		D3DPresentParams.BackBufferHeight=600;
    		D3DPresentParams.BackBufferFormat=D3DFMT_X8R8G8B8;
    		D3DPresentParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
    		D3DPresentParams.hDeviceWindow=hWnd;
    HRESULT hResult = pDirect3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);
    if(hResult!=D3D_OK)
    {
    MessageBox(hWnd, L"CheckDeviceType failed!", L"", MB_OK);
    goto EXIT;
    }
    	
     hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
    if(hResult!=D3D_OK)
    		{
    		MessageBox(hWnd, L"CreateDevice failed!", L"", MB_OK);
    		goto EXIT;
    		}
    The display format is compatible with my system. The file compiles, but for some reason, I can NOT get the CreateDevice call to work. The DirectX pointers are declared as global variables in the program. I am using Visual Studio 2005. Just a FYI, the gotos are in there for debugging purposes. Any help is greatly appreciated.

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    are you linking with d3d9.lib and including d3d9.h ?
    make sure d3d8.lib isnt being linked instead/also.

    also, you may want to put in some error handlign code to better handle results other than DD_OK. It may be a recoverable error.

    D3DERR_INVALIDCALL means one of your parameters is invalid

    D3DERR_NOTAVAILABLE means your card doesnt support soem feature you asked for.

    D3DERR_OUTOFVIDEOMEMORY means you dont have enough video memory to perform the action.

    use a simple switch statement to report the specific error (via messagebox) to gain more insight

    offhand id also suggest you change
    Code:
     hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
    to:
    Code:
     hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
    Some cards dont seem to like doing software vertex processing in full screen mode.
    Last edited by abachler; 05-29-2007 at 02:59 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    "cannot get to work" is far too vague for any kind of meaningful help. What errors are you getting? Does it compile? None of us can read minds... at least, I hope not...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why use Direct3D?
    By m3rk in forum Tech Board
    Replies: 42
    Last Post: 05-22-2009, 10:08 AM
  2. CreateDevice returning D3DERR_NOTAVAILABLE
    By cboard_member in forum Game Programming
    Replies: 5
    Last Post: 05-28-2006, 11:09 AM
  3. Need help with getting DirectX 9.0 initilization
    By DarkMortar in forum Windows Programming
    Replies: 7
    Last Post: 05-09-2006, 09:58 PM
  4. Creating a 2D GUI using Direct3D
    By codec in forum Game Programming
    Replies: 8
    Last Post: 09-23-2004, 12:57 PM
  5. Direct3D vs. OpenGL
    By PorkyChop in forum Game Programming
    Replies: 22
    Last Post: 12-08-2002, 12:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21