I'm getting the error "WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT" so clearly I'm doing something wrong, I just don't understand what :\
Do you guys see anything wrong in my code?
//Create D3d device, context, swapChain
ID3D11Device* d3dDevice;
ID3D11DeviceContext* d3dContext;
IDXGISwapChain* swapChain;
DXGI_SWAP_CHAIN_DESC swapChainDesc{};
swapChainDesc.BufferDesc.Width = appWidth;
swapChainDesc.BufferDesc.Height = appHeight;
swapChainDesc.BufferDesc.RefreshRate = { 60,1 };
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED;
swapChainDesc.SampleDesc.Count = 1; // for AntiAliasing
swapChainDesc.SampleDesc.Quality;// for AntiAliasing
swapChainDesc.BufferCount = 2;
swapChainDesc.OutputWindow = appWindow;
swapChainDesc.Windowed = true;
if (HRESULT hr = D3D11CreateDeviceAndSwapChain(nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
D3D11_CREATE_DEVICE_BGRA_SUPPORT,
nullptr,
0,
D3D11_SDK_VERSION,
&swapChainDesc,
&swapChain,
&d3dDevice,
nullptr,
&d3dContext
); hr != S_OK) {
printError("Error during D3d initialization", hr);
return 1;
}
//Create D2d factory, renderTarget
ID2D1Factory* d2dFactory;
ID2D1RenderTarget* renderTarget;
if (HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &d2dFactory); hr != S_OK)
{
printError("Error during D2d factory creation", hr);
return 1;
}
//get backBuffer
IDXGISurface* dxgiSurface;
if (HRESULT hr = swapChain->GetBuffer(0, __uuidof(dxgiSurface), reinterpret_cast<void**>(&dxgiSurface)); hr != S_OK)
{
printError("Error retrieving dxgiSurface", hr);
return 1;
}
float dpiX, dpiY;
d2dFactory->GetDesktopDpi(&dpiX, &dpiY);
D2D1_RENDER_TARGET_PROPERTIES props{};
props.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
props.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED);
props.dpiX = dpiX;
props.dpiY = dpiY;
if (HRESULT hr = d2dFactory->CreateDxgiSurfaceRenderTarget(dxgiSurface, props, &renderTarget); hr != S_OK)
{
printError("CreateDxgiSurfaceRenderTarget() function failed", hr); //THIS FAIL
system("pause"); //THIS FAIL
return 1; //THIS FAIL
}