Thread: Direct3D CreateDevice

  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,195
    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.

  3. #3
    "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
Website Security Test