Jump to content
  • Advertisement
Sign in to follow this  
oldgregg

Could Not initialize Direct3D

This topic is 2055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

I'm following this tutorial:
http://rastertek.com/dx11tut04.html

And I've done everything, However when I hit play I get the pop up message.
'Could Not initialize Direct3D'

The only thing I can think of is, Could this be because I'm using a GTX 295? I know it's not DX11 compat. But I've done all my other DX11 programming on this and it's been fine!

Also I think the problem can been narrowed down to the D3DClass.cpp
on line 171.


result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);///////////These are mostly 0...



Any help would be really appreciated, Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I've also done a few tutorials on that site and if your card can't support DX11 that error message will show up. You can go pass this by changing to your CPU to take care of the graphics, but this will lower your fps to like 0.1/s and it will take a lot of time to start the project. But it works.

result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

To change to run it on the CPU instead you change this part
D3D_DRIVER_TYPE_HARDWARE[/quote] to D3D_DRIVER_TYPE_REFERENCE

so it will be like this: result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

This should fix your problem. If it doesn't work then there is something else in your code that isn't working, but I'm pretty sure this will fix it since me and a friend did a project together on one computer that didn't support DX11 and thus had to do this change.

Hope it works, gl! :D

Share this post


Link to post
Share on other sites

I've also done a few tutorials on that site and if your card can't support DX11 that error message will show up. You can go pass this by changing to your CPU to take care of the graphics, but this will lower your fps to like 0.1/s and it will take a lot of time to start the project. But it works.

result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

To change to run it on the CPU instead you change this part
D3D_DRIVER_TYPE_HARDWARE
to D3D_DRIVER_TYPE_REFERENCE

so it will be like this: result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, &featureLevel, 1,
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);

This should fix your problem. If it doesn't work then there is something else in your code that isn't working, but I'm pretty sure this will fix it since me and a friend did a project together on one computer that didn't support DX11 and thus had to do this change.

Hope it works, gl! biggrin.png
[/quote]


That's done it! Thanks so much!
Is it just the way that that specific code runs that ruins it, Because all my other work has worked fine! I've had the multicoloured triangle going and everything lol.

Share this post


Link to post
Share on other sites

That's done it! Thanks so much!
Is it just the way that that specific code runs that ruins it, Because all my other work has worked fine! I've had the multicoloured triangle going and everything lol.


Glad I could help!

I have no idea, really. If you followed his tutorials from the start then you should've been doing DX11 the entire time. But even if you code in DX11 you can still adjust flags to run on earlier versions of DX, maybe that's what you've done earlier...not really sure, I find it a bit odd that your triangle worked in DX11 when your card doesn't support it ^^

Share this post


Link to post
Share on other sites
Well what does your other "working" code do to initialize the device? That would seem the logical starting point to investigate the issue (unless you don't want to find out..)

Share this post


Link to post
Share on other sites

Well what does your other "working" code do to initialize the device? That would seem the logical starting point to investigate the issue (unless you don't want to find out..)



hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );


That's the code I'm using in the other project. I think it's detecting I can only run DX 10.1 and is selecting that.
Full code listing of InitDevice:

HRESULT Graphics::InitDevice(HWND mHWnd)
{
HRESULT hr = S_OK;
RECT rc;
GetClientRect( mHWnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
UINT createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_DRIVER_TYPE driverTypes[] =
{
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = ARRAYSIZE( driverTypes );
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};
UINT numFeatureLevels = ARRAYSIZE( featureLevels );
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = mHWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ )
{
g_driverType = driverTypes[driverTypeIndex];
hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext );
if( SUCCEEDED( hr ) )
break;
}
if( FAILED( hr ) )
return hr;
// Create a render target view
ID3D11Texture2D* pBackBuffer = NULL;
hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
pBackBuffer->Release();
if( FAILED( hr ) )
return hr;
g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL );
// Setup the viewport
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)width;
vp.Height = (FLOAT)height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
g_pImmediateContext->RSSetViewports( 1, &vp );
}

Share this post


Link to post
Share on other sites
Does tutorial 4 require a D3D11-exclusive feature? (like tessellation, etc..)? If not, then using feature levels should work equally well for this tutorial (the code is longer, but you could write a helper function that you can reuse in multiple projects).

Share this post


Link to post
Share on other sites

Does tutorial 4 require a D3D11-exclusive feature? (like tessellation, etc..)? If not, then using feature levels should work equally well for this tutorial (the code is longer, but you could write a helper function that you can reuse in multiple projects).


I don't think tutorial 4 does no, Even that tutorial is only drawing a triangle to the screen, But it set up buffers and other things in a way I found much better.

I might actually do what you said and write the helper function though! good call!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!