This is the error
D3D11 ERROR: ID3D11Device::CreateRenderTargetView: A RenderTargetView cannot be created of a Resource that did not specify the RENDER_TARGET BindFlag. [ STATE_CREATION ERROR #138: CREATERENDERTARGETVIEW_INVALIDRESOURCE]
D3D11 ERROR: ID3D11Device::CreateRenderTargetView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #140: CREATERENDERTARGETVIEW_INVALIDARG_RETURN]
So as i see here i need to set the BindFlag of the backBuffer to D3D11_BIND_RENDER_TARGET, but in all the tutorial i saw nobody is doing it, they all create the render target view by using this code
hr=m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&m_backBuffer));
if (FAILED(hr)) MessageBox(0, L"Failed get buffer", 0, 0);
hr=m_device->CreateRenderTargetView(m_backBuffer, NULL, &m_renderTargetView);
if (FAILED(hr)) MessageBox(0, L"Failed to create rendertargetview", 0, 0);
And nobody, nowhere is doing as the msdn site says, that the render target view must be created with this specific flag: D3D11_BIND_RENDER_TARGET
So I tried doing it by myself.
I created a texture2d desc like this for the back buffer:
D3D11_TEXTURE2D_DESC backBufferDescription;
backBufferDescription.BindFlags = D3D11_BIND_RENDER_TARGET;
backBufferDescription.ArraySize = 1;
backBufferDescription.CPUAccessFlags = 0;
backBufferDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
backBufferDescription.Height = 600;
backBufferDescription.Width = 800;
backBufferDescription.MipLevels = 1;
backBufferDescription.MiscFlags = 0;
backBufferDescription.SampleDesc.Quality = 0;
backBufferDescription.SampleDesc.Count = 1;
backBufferDescription.Usage = D3D11_USAGE_DEFAULT;
m_device->CreateTexture2D(&backBufferDescription, NULL, &m_backBuffer);
if (FAILED(hr))
MessageBox(0, L"Fallito back buffer desc", 0, 0);
And it doesn't work the same.
Help please