if( FAILED( d3d->InitDevice(window->GetHwnd()) ) )
{
MessageBox(window->GetHwnd(), "error", "", MB_OK);
d3d->Cleanup();
return 0;
}
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.
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;