当前位置:网站首页>D3D10 screenshot function saves texture to local

D3D10 screenshot function saves texture to local

2022-06-22 05:57:00 Wangjianbo 09

Date 20200311 By Wjb

Go straight to the code :

        ID3D10Resource* pScreen;
		mRenderTargetView->GetResource(&pScreen);
		D3D10_TEXTURE2D_DESC texDesc;
		texDesc.ArraySize = 1;
		texDesc.CPUAccessFlags = 0;
		texDesc.Width = (unsigned int)mClientWidth;
		texDesc.Height = (unsigned int)mClientHeight;;
		texDesc.SampleDesc.Count = 8;
		texDesc.SampleDesc.Quality = 0;
		texDesc.ArraySize = 1;
		texDesc.MipLevels = 1;
		texDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
		texDesc.SampleDesc.Count = 1;
		texDesc.SampleDesc.Quality = 0;
		texDesc.Usage = D3D10_USAGE_DEFAULT;
		texDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;

		ID3D10Texture2D *texture;
		HRESULT hr = md3dDevice->CreateTexture2D(&texDesc, 0, &texture);
		md3dDevice->CopyResource(texture, pScreen);

		char filename [245];
		sprintf(filename, "TestFile%d.dds", name);
		hr = D3DX10SaveTextureToFileA(texture, D3DX10_IFF_DDS, filename);

		texture->Release();
		pScreen->Release();

I keep things DDS Format file , stay VS The opening effect in is shown in the following figure

I attached the function source code , Environmental Science VS2013 d3d10. Download address :

原网站

版权声明
本文为[Wangjianbo 09]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220534436497.html