DirectX:如何获得正确的框架?

时间:2018-03-12 10:06:07

标签: c++ directx capture direct3d9

我想要捕获有立体声应用的桌面。

我的代码

IDirect3D9 *d3d = nullptr;
IDirect3DDevice9* device = nullptr;
IDirect3DSurface9 *surfaceMono = nullptr, *surfaceLeft=nullptr, 
*surfaceRight=nullptr, *surfaceFront=nullptr;
D3DDISPLAYMODE mode;
D3DPRESENT_PARAMETERS parameters;
ZeroMemory(&mode, sizeof(mode));
ZeroMemory(&parameters, sizeof(parameters));

HRESULT result=S_OK;`

d3d = Direct3DCreate9(D3D_SDK_VERSION);

result = d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);

parameters.Windowed = true;
parameters.BackBufferCount = D3DPRESENT_BACK_BUFFERS_MAX;
parameters.BackBufferHeight = mode.Height;
parameters.BackBufferWidth = mode.Width;
parameters.SwapEffect = D3DSWAPEFFECT_FLIP;
parameters.hDeviceWindow = NULL;
    parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;


result = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,D3DCREATE_HARDWARE_VERTEXPROCESSING, &parameters, &device);

    result = device->CreateOffscreenPlainSurface(mode.Width, mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surfaceMono, nullptr)
result = device->CreateOffscreenPlainSurface(mode.Width, mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surfaceLeft, nullptr)
result = device->CreateOffscreenPlainSurface(mode.Width, mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surfaceRight, nullptr)
    result = device->CreateOffscreenPlainSurface(mode.Width,mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surfaceFront, nullptr)

    result = device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &surfaceMono);
result = D3DXSaveSurfaceToFile(FilePathMono, D3DXIFF_PNG, surfaceMono, NULL, NULL);

result = device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_LEFT, &surfaceLeft);
result = D3DXSaveSurfaceToFile(FilePathLeft, D3DXIFF_PNG, surfaceLeft, NULL, NULL);

result = device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_RIGHT, &surfaceRight);
result = D3DXSaveSurfaceToFile(FilePathRight, D3DXIFF_PNG, surfaceRight, NULL, NULL);

result = device->GetFrontBufferData(0,surfaceFront);
result = D3DXSaveSurfaceToFile(FilePathFront, D3DXIFF_PNG, surfaceFront, NULL, NULL);`

在我的输出中,我得到空的后缓冲区,只留下前面的帧。 我试图在循环中捕获帧并增加CreateOffscreenPlainSurface,但它没有帮助。

如何获得正确的框架?

(win 7,quadro,3d vision)

0 个答案:

没有答案