gpt4 book ai didi

screenshot - 如何在DirectX 10中将后缓冲保存到文件中?

转载 作者:行者123 更新时间:2023-12-03 08:20:13 27 4
gpt4 key购买 nike

我想使用DirectX 10逐帧渲染视频。这些帧稍后将由其他一些工具(例如mencoder或ffmpeg)进行处理。

使用D3DXSaveSurfaceToFile在DX9中这样做没有问题。

现在,在DX10中,我找到了D3DX10SaveTextureToFile,但是用它来保存我的后缓冲区没有运气。

我使用以下代码:

ID3D10Resource *backbufferRes;
_defaultRenderTargetView->GetResource(&backbufferRes);

D3D10_TEXTURE2D_DESC texDesc;
texDesc.ArraySize = 1;
texDesc.BindFlags = 0;
texDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
texDesc.Format = backbufferSurfDesc.Format;
texDesc.Height = backbufferSurfDesc.Height;
texDesc.Width = backbufferSurfDesc.Width;
texDesc.MipLevels = 1;
texDesc.MiscFlags = 0;
texDesc.SampleDesc = backbufferSurfDesc.SampleDesc;
texDesc.Usage = D3D10_USAGE_STAGING;

ID3D10Texture2D *texture;
HRESULT hr;
V( _device->CreateTexture2D(&texDesc, 0, &texture) );
_device->CopyResource(texture, backbufferRes);

V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_DDS, filename) );
texture->Release();

这将创建一个.dds图像,我无法通过任何DDS View /编辑器打开该图像。

我的代码有什么问题?

最佳答案

所有的功劳归于gamedev.net的坟墓。

现在,问题是:

  • texDesc.CPUAccessFlags应为0
  • texDesc.Format应该是DXGI_FORMAT_R8G8B8A8_UNORM
  • texDesc.SampleDesc.Count应为1
  • texDesc.SampleDesc.Quality应为0
  • texDesc.Usage应该是D3D10_USAGE_DEFAULT

  • 这样 D3DX10SaveTextureToFile将保存到BMP甚至保存到PNG。

    完整的代码是:
    HRESULT hr;
    ID3D10Resource *backbufferRes;
    _defaultRenderTargetView->GetResource(&backbufferRes);

    D3D10_TEXTURE2D_DESC texDesc;
    texDesc.ArraySize = 1;
    texDesc.BindFlags = 0;
    texDesc.CPUAccessFlags = 0;
    texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    texDesc.Width = 640; // must be same as backbuffer
    texDesc.Height = 480; // must be same as backbuffer
    texDesc.MipLevels = 1;
    texDesc.MiscFlags = 0;
    texDesc.SampleDesc.Count = 1;
    texDesc.SampleDesc.Quality = 0;
    texDesc.Usage = D3D10_USAGE_DEFAULT;

    ID3D10Texture2D *texture;
    V( _device->CreateTexture2D(&texDesc, 0, &texture) );
    _device->CopyResource(texture, backbufferRes);

    V( D3DX10SaveTextureToFile(texture, D3DX10_IFF_PNG, L"test.png") );
    texture->Release();
    backbufferRes->Release();

    关于screenshot - 如何在DirectX 10中将后缓冲保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4120108/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com