• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
oldgregg

Could Not initialize Direct3D

12 posts in this topic

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.

[CODE]
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...
[/CODE]


Any help would be really appreciated, Thanks!
1

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
[quote]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
2

Share this post


Link to post
Share on other sites
[quote name='PwFClockWise' timestamp='1354395788' post='5006092']
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
[quote]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! [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
[/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.
0

Share this post


Link to post
Share on other sites
[quote name='riverreal' timestamp='1354395872' post='5006094']
You downloaded the source code directly? or copied it by hand?
[/quote]

I tried both, Same result each time!
0

Share this post


Link to post
Share on other sites
[quote name='oldgregg' timestamp='1354396731' post='5006096']
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.
[/quote]

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 ^^
0

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..)
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1354411452' post='5006170']
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..)
[/quote]

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

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:
[CODE]
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 );
}
[/CODE]
0

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).
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1354412856' post='5006178']
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).
[/quote]

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!
0

Share this post


Link to post
Share on other sites
Make sure that you're definitely ending up picking the 10 feature level. You'll also need to change the shader profile argument for D3DX11CompileFromFile. It's probably "ps_5_0" / "vs_5_0" right now. Change it accordingly -- on your card you'd need to use 4 instead.
2

Share this post


Link to post
Share on other sites
I think your problem is in the "1" in this line:
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1,

That parameter tells the function how many "features levels" are in "featureLevel", you are passing 1, so if your featureLevel array looks like this:
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
};

You are asking for feature level 11.

To fix, pass 3 instead of 1 and the other feature levels will also be considered by the function.
2

Share this post


Link to post
Share on other sites
[quote name='clashie' timestamp='1354501565' post='5006471']
Make sure that you're definitely ending up picking the 10 feature level. You'll also need to change the shader profile argument for D3DX11CompileFromFile. It's probably "ps_5_0" / "vs_5_0" right now. Change it accordingly -- on your card you'd need to use 4 instead.
[/quote]

It wasn't doing this, MY GPU doesn't support Feature level11 so I needed 10/10.1:
[CODE]
// Set the feature level to DirectX 11.
featureLevel = D3D_FEATURE_LEVEL_10_0;
// Create the swap chain, Direct3D device, and Direct3D device context.
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &amp;featureLevel, 1,
D3D11_SDK_VERSION, &amp;swapChainDesc, &amp;m_swapChain, &amp;m_device, NULL, &amp;m_deviceContext); //Used for GPU
[/CODE]
Then I needed to add a flag to my shader code 'D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY' and change it to use 'vs_4_0' :
[CODE]
// Compile the vertex shader code.
result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "LightVertexShader", "vs_4_0", D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY, 0, NULL,
&amp;vertexShaderBuffer, &amp;errorMessage, NULL);
[/CODE]
(Same for PS)

Sorted now, It all runs on GPU and not CPU emulation :3!


EDIT: Thanks for all your help guys! Edited by oldgregg
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0