Sign in to follow this  
Amaz1ng

DIrectX10 Error

Recommended Posts

Amaz1ng    131
I'm trying to learn DirectX10 and am starting to build a basic framework. Only thing is that it keeps failing on the part below:

[code]
if( FAILED( d3d->InitDevice(window->GetHwnd()) ) )
{
MessageBox(window->GetHwnd(), "error", "", MB_OK);
d3d->Cleanup();
return 0;
}
[/code]

and here....I know it's failing right after D3D10CreateDeviceAndSwapChain but is there anything else that anyone sees is wrong. I just started yesterday so I need some pointers.
[code]
HRESULT hr = S_OK;

//get the height/width of the client window
RECT rc;
GetClientRect( hwnd, &rc );
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;

//swap chain and desc
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 2;
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 = hwnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;

//creating the device and swap chain
hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &sd, &swapchain, &device);

if( FAILED( hr ) )
return hr;

//setting the backbuffer to the swap chain
hr = swapchain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&backBuffer );
if( FAILED( hr ) )
return hr;

hr = device->CreateRenderTargetView(backBuffer, 0, &renderTarget);
backBuffer->Release();
if( FAILED( hr ) )
return hr;

//Create the depth/stencil buffer - set render target
depthDesc.ArraySize = sizeof(D3D10_TEXTURE2D_DESC);
depthDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depthDesc.Width = width;
depthDesc.Height = height;
depthDesc.CPUAccessFlags = 0;
depthDesc.Usage = D3D10_USAGE_DEFAULT;
depthDesc.MipLevels = 0;
depthDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
depthDesc.MiscFlags = 0;

hr = device->CreateTexture2D(&depthDesc, NULL , &depthStencil);
if( FAILED( hr ) )
return hr;

hr = device->CreateDepthStencilView(depthStencil, NULL, &dsView);
if( FAILED( hr ) )
return hr;

device->OMSetRenderTargets(1, &renderTarget, dsView);

//viewport
vp.TopLeftX = 0;
vp.TopLeftY = 0;
vp.Width = width;
vp.Height = height;
vp.MaxDepth = 1;
vp.MinDepth = 0;
device->RSSetViewports(1, &vp);

return S_OK;

[/code]

Share this post


Link to post
Share on other sites
sepul    257
try setting, BufferUsage = DXGI_USAGE_BACK_BUFFER

and remember to add, D3D10_CREATE_DEVICE_DEBUG to [font=CourierNew, monospace][size=2][i]D3D10CreateDeviceAndSwapChain's [/i][/size][/font]Flags to get debug errors/warnings on your output window.

Share this post


Link to post
Share on other sites
Tordin    625
Add your .exe to the debug program.

the debug program will output all the info on what went wrong in the output window in MSVS.

you can find the debug program in the ;
Microsoft DirectX SDK (June 2010)\Utilities\bin\x86\dxcpl.exe

start that and add your program, and force the debug on.

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