I have the following code:
HRESULT result = S_OK;
ID3D11Device* g_pd3dDevice = NULL;
IDXGISwapChain* g_pSwapChain = NULL;
ID3D11DeviceContext* g_pImmediateContext = NULL;
D3D_FEATURE_LEVEL FeatureLevelsSupported;
RECT deminsions;
GetClientRect(hwnd, &deminsions);
LONG width = deminsions.right - deminsions.left;
LONG height = deminsions.top - deminsions.bottom;
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = static_cast<unsigned int>(width);
sd.BufferDesc.Height = static_cast<unsigned int>(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;
D3D_FEATURE_LEVEL FeatureLevelsRequested[] =
{
D3D_FEATURE_LEVEL_9_1,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_11_0
};
result = D3D11CreateDeviceAndSwapChain( NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
FeatureLevelsRequested,
3,
D3D11_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice,
&FeatureLevelsSupported,
&g_pImmediateContext );
if(FAILED(result)) return -1;
ID3D11RenderTargetView* p_BackBufferTarget = NULL;
ID3D11Texture2D* p_RT;
result = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&p_RT);
if(FAILED(result)) return -2;
result = g_pd3dDevice->CreateRenderTargetView(p_RT, 0, &p_BackBufferTarget);
if(FAILED(result)) return -3;
if(p_RT) p_RT->Release(); p_RT = NULL;
g_pImmediateContext->OMSetRenderTargets(1, &p_BackBufferTarget, 0);
D3D11_VIEWPORT viewport;
viewport.Height = static_cast<float>(height);
viewport.Width = static_cast<float>(width);
viewport.MaxDepth = 1.0f;
viewport.MinDepth = 0.0f;
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
g_pImmediateContext->RSSetViewports(1, &viewport);
UpdateWindow(hwnd);
the program fails and returns -1 which means there is something wrong with this:
result = D3D11CreateDeviceAndSwapChain( NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
FeatureLevelsRequested,
3,
D3D11_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice,
&FeatureLevelsSupported,
&g_pImmediateContext );
But I'm not sure what?
Thanks, thefatshizms