0
votes

I am trying to run an exe from this Directx-11 tutorial website:tutorial5 (exe at the end of the page), but I get the error "Could not initialize Direct3d".

I get the same error when I download the solution and run it on Visual Studio 2013 or Visual Studio 2010.

  • I have installed the latest DirectX (installed using "DirectX End-User Runtime Web Installer": link)
  • I also installed DirectX 9 SDK from here: DirectX 9 SDK June 2010
  • dxdiag shows Direct3d "Enabled".
  • I updated the "Intel HD Graphics library on core i5" to the latest driver.

What am I missing? How can I run Directx-11 applications on my machine?

Thanks!

1

1 Answers

0
votes

The error happened here, you should check the result of Initialize function to see what's the error.

// Initialize the Direct3D object.
result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
if(!result)
{
    MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
    return false;
}

Another useful tip is to turn on DEBUG mode when create device and swap chain. Try the following code the enable debug mode when creating device(in d3dclass.cpp, add the following code before calling D3D11CreateDeviceAndSwapChain, and don't forget to set the third parameter of this function to flags)

    UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

#if defined( DEBUG ) || defined( _DEBUG )
    flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif 

// Create the swap chain, Direct3D device, and Direct3D device context.
    result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, flags, 0, &featureLevel, 1, 
        D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
    if(FAILED(result))
    {
        return false;
    }

Build and run the program in debug mode and see the output in VS's output window.