游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1363|回复: 1

怎么在DXUT程序中保存一帧到文件中?

[复制链接]

5

主题

12

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2007-11-2 23:38:00 | 显示全部楼层 |阅读模式
这是我找到的代码,是8.1的
void TakeScreenShot(IDirect3DDevice8* device, char* file_name, int screenx, int screeny)
{
   IDirect3DSurface8* frontbuf; //this is our pointer to the memory location containing our copy of the
                                //front buffer

   //now we create the image that our screen shot will be copied into
   //NOTE: Surface format of the front buffer is D3DFMT_A8R8G8B8 when it is returned
   device->CreateImageSurface(screenx, screeny, D3DFMT_A8R8G8B8, &frontbuf);

   //now we copy the front buffer into our surface
   HRESULT hr = device->GetFrontBuffer(frontbuf);

   //error checking
   if(hr != D3D_OK)
   {
      //do error handling etc...
      frontbuf->Release(); //release the surface so there is no memory leak
      return;
   }

   //now write our screen shot to a bitmap file
   //the last 2 params are NULL because we want the entire front buffer and no palette
   D3DXSaveSurfaceToFile(file_name, D3DXIFF_BMP, frontbuf, NULL, NULL);

   //release the surface so there is no memory leak
   frontbuf->Release();
}

不过我的是9.0的。有些函数的参数改变了。
HRESULT ScreenGrab(IDirect3DDevice9*  pDev,LPCWSTR fileName)
{
        HRESULT hr;

        // get display dimensions
        // this will be the dimensions of the front buffer
        D3DDISPLAYMODE mode;
        UINT  iSwapChain = 0;
        if (FAILED(hr=pDev->GetDisplayMode(iSwapChain,&mode)))
                return hr;

       
        // create the image surface to store the front buffer image
        // note that call to GetFrontBuffer will always convert format to A8R8G8B8
        LPDIRECT3DSURFACE9 surf;

        if (FAILED(hr=pDev->CreateRenderTarget(mode.Width,mode.Height,
                D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE , 0, false, &surf ,NULL)))
                return hr;
        //pDev->CreateDepthStencilSurface
        //pDev->
       

//Next, this surface is passed to the GetFrontBuffer() method of the device, which will copy the entire screen into our image buffer:

        // read the front buffer into the image surface
            hr=pDev->GetFrontBufferData(iSwapChain,surf);
        if ( FAILED(hr=pDev->GetFrontBufferData(iSwapChain,surf)))
        {
                surf->Release();
                return hr;
        }


//Finally, we call D3DXSaveSurfaceToFile() to create the BMP file, and release the temporary image surface:

        // write the entire surface to the requested file
        hr=D3DXSaveSurfaceToFile(L"g.jpg",D3DXIFF_JPG,surf,NULL,NULL);

        // release the image surface
        surf->Release();

        // return status of save operation to caller
        return hr;
}

不过最后没有保存出任何一个JPG的文件。请问这个函数在那里失败了。是我在9.0下面的参数错了吗?
谁有相关的程序或者方法请指导一下。谢谢啊

1

主题

149

帖子

149

积分

注册会员

Rank: 2

积分
149
QQ
发表于 2007-11-3 17:29:00 | 显示全部楼层

Re:怎么在DXUT程序中保存一帧到文件中?

返回值hr是什么?你确定它保存的文件目录就是你想象中的目录??
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-19 03:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表