How do you create swap chain I always get failure on the CreateSwapChainForHwnd call
Code:
DXGI_SWAP_CHAIN_DESC1 desc;
ZeroMemory(&desc, sizeof(DXGI_SWAP_CHAIN_DESC1));
desc.BufferCount = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.SampleDesc.Count = 1; //multisampling setting
desc.SampleDesc.Quality = 0; //vendor-specific flag
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
desc.Width = 300;
desc.Height = 300;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// Create the DXGI device object to use in other factories, such as Direct2D.
IDXGIDevice3* dxgiDevice;
// Create swap chain.
IDXGIAdapter* adapter;
IDXGIFactory2* factory;
IDXGISwapChain1* swapchain;
hr = device->QueryInterface(__uuidof(IDXGIDevice3), (void**)&dxgiDevice);
hr = dxgiDevice->GetAdapter(&adapter);
if (SUCCEEDED(hr))
{
hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&factory);
hr = factory->CreateSwapChainForHwnd(
device,
m_amahwnd,
&desc,
NULL,
NULL,
&swapchain
);
try
{
if (!SUCCEEDED(hr))
{
throw(std::invalid_argument("Blah"));
}
}
catch (std::invalid_argument& blah)
{
MessageBox(m_amahwnd, L"Blah", L"blah", MB_OK);
}
I don't know how to get a swap chain created, should I go back and do a CreateDevice*AND*SwapChain?