创建:
dev->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_pTexture, NULL);
// 顺带的z-buffer(对于UI而言,可以忽略,关闭z-buffer test就好了)
dev->CreateDepthStencilSurface(512, 512, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &g_pDepthStencil, NULL);
使用:
//记录原始缓冲区
LPDIRECT3DSUFACE9 pFrameBufferBackup, pDepthBufferBackup;
dev->GetRenderTarget(0, &pFrameBufferBackup);
pFrameBufferBackup->Release();// 不明其义
dev->GetDepthStencilSurface(&pDepthBufferBackup);
pDepthBufferBackup->Release();// 不明其义
LPDIRECT3DSURFACE9 pSurface;
g_pTexture->GetSurfaceLevel(0, &pSurface);
dev->SetRenderTarget(0, pSurface);
dev->SetDepthStencilSurface(g_pDepthStencil);
dev->Clear(xxxx);// 清除缓冲和画面,代码略
Render();// 渲染,代码略
pSurface->Release();// 依旧不明其义,可能只是减少接口指针引用数吧
dev->SetRenderTarget(0, pFrameBufferBackup);
dev->SetDepthStencilSurface(pDepthBufferBackup);
以上,将Render()内的对象渲染到了Texture里面
之后使用之即可
dev->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &g_pTexture, NULL);
// 顺带的z-buffer(对于UI而言,可以忽略,关闭z-buffer test就好了)
dev->CreateDepthStencilSurface(512, 512, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, FALSE, &g_pDepthStencil, NULL);
使用:
//记录原始缓冲区
LPDIRECT3DSUFACE9 pFrameBufferBackup, pDepthBufferBackup;
dev->GetRenderTarget(0, &pFrameBufferBackup);
pFrameBufferBackup->Release();// 不明其义
dev->GetDepthStencilSurface(&pDepthBufferBackup);
pDepthBufferBackup->Release();// 不明其义
LPDIRECT3DSURFACE9 pSurface;
g_pTexture->GetSurfaceLevel(0, &pSurface);
dev->SetRenderTarget(0, pSurface);
dev->SetDepthStencilSurface(g_pDepthStencil);
dev->Clear(xxxx);// 清除缓冲和画面,代码略
Render();// 渲染,代码略
pSurface->Release();// 依旧不明其义,可能只是减少接口指针引用数吧
dev->SetRenderTarget(0, pFrameBufferBackup);
dev->SetDepthStencilSurface(pDepthBufferBackup);
以上,将Render()内的对象渲染到了Texture里面
之后使用之即可