1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
bool Application::InitD3D(){
D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0 };
D3D_FEATURE_LEVEL featureLevelOut;
UINT numFeatureLevels = _countof(featureLevels);
// Create a struct to hold information about the swap chain
DXGI_SWAP_CHAIN_DESC scd;
//Clear out the chain for use
SecureZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.Width = mWndWidth;
scd.BufferDesc.Height = mWndHeight;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = mHwnd;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.Windowed = TRUE;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
// I feel like I am calling this wrong...
D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
NULL,
NULL,
D3D11_SDK_VERSION,
&scd,
&mSwapChain,
&mDevice,
NULL,
&mDeviceContext
);
// Commented this one out, just haven't omitted it yet.
/*D3D11CreateDevice(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
&featureLevels[0],
numFeatureLevels,
D3D11_SDK_VERSION,
&mDevice,
&featureLevelOut,
&mDeviceContext
);*/
if (!mDevice){
MessageBoxA(0, "mDevice Failed!", 0, 0);
return false;
}
if (!mDeviceContext){
MessageBoxA(0, "mDeviceContext Failed!", 0, 0);
return false;
}
// Also commented this out. Probably should have omitted it too.
/*IDXGIFactory* factory;
CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
IUnknown* device = nullptr;
device = static_cast<IUnknown*>(device);
factory->CreateSwapChain(device, &scd, &mSwapChain);*/
// BOOM! Direct3D == failed to initialize
if (!mSwapChain){
MessageBoxA(0, "mSwapChain Failed!", 0, 0);
return false;
}
// Set Render Target
ID3D11Texture2D *pBackBuffer = 0;
mSwapChain->GetBuffer(0, _uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBackBuffer));
mDevice->CreateRenderTargetView(pBackBuffer, NULL, &mRenderTargetView);
pBackBuffer->Release();
// Set RenderTarget as back buffer
mDeviceContext->OMSetRenderTargets(1, &mRenderTargetView, NULL);
// Set Viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = mWndWidth;
viewport.Height = mWndHeight;
mDeviceContext->RSSetViewports(1, &viewport);
return true;
}
|