试了下,果然可以。
在渲染完所有东东后(Present之前)
获得BackBuffer表面
然后用D3DX的函数保存
void ScreenShot (char *filename)
{
IDirect3DSurface9 *tmp = NULL;
IDirect3DSurface9 *back = NULL;
//生成固定颜色模式的离屏表面(Width和 Height为屏幕或窗口的宽高)
D3D9Device->CreateOffscreenPlainSurface(Width, Height, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tmp, NULL);
// 获得BackBuffer的D3D Surface
D3D9Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &back);
// Copy一下,,需要时转换颜色格式
D3DXLoadSurfaceFromSurface(tmp, NULL, NULL, back, NULL, NULL, D3DX_FILTER_NONE, 0);
// 保存成BMP格式
D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, tmp, NULL, NULL);
// 释放Surface,防止内存泄漏
SAFE_RELEASE(tmp);
SAFE_RELEASE(back);
}
文件格式可以为:
D3DXIFF_BMP
Microsoft Windows bitmap (BMP) file format.
D3DXIFF_JPG
Joint Photographics Experts Group (JPEG) compressed file format.
D3DXIFF_PNG
Portable Network Graphics (PNG) file format.
D3DXIFF_DDS
Microsoft DirectDraw surface (DDS) file format.
D3DXIFF_DIB
Windows device-independent bitmap (DIB) file format.
D3DXIFF_HDR
High dynamic range file format.
D3DXIFF_PFM
Portable float map file format.