【发布时间】:2015-07-18 15:08:33
【问题描述】:
我正在寻找一种将文本绘制到 IDirect3DSurface9 实现类的方法。我的目标是在截图中写入一些文本,比如截图的时间。
制作我的游戏截图的原始(工作)代码:
void CreateScreenShot(IDirect3DDevice9* device, int screenX, int screenY)
{
IDirect3DSurface9* frontbuf; //this is our pointer to the memory location containing our copy of the front buffer
// Creation of the surface where the screen shot will be copied to
device->CreateOffscreenPlainSurface(screenX, screenY, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &frontbuf, NULL);
// Copying of the Back Buffer to our surface
HRESULT hr = device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &frontbuf);
if (hr != D3D_OK)
{
frontbuf->Release();
return;
}
// Aquiring of the Device Context of the surface to be able to draw into it
HDC surfaceDC;
if (frontbuf->GetDC(&surfaceDC) == D3D_OK)
{
drawInformationToSurface(surfaceDC, screenX);
frontbuf->ReleaseDC(surfaceDC);
}
// Saving the surface to a file. Creating the screenshot file
D3DXSaveSurfaceToFile("ScreenShot.bmp", D3DXIFF_BMP, frontbuf, NULL, NULL);
}
现在您可以看到,我创建了一个名为 drawInformationToSurface(HDC surfaceDC, int screenX) 的辅助方法,它应该在将当前时间保存到 HDD 之前将其写入 Surface。
void drawInformationToSurface(HDC surfaceDC, int screenX)
{
// Creation of a new DC for drawing operations
HDC memDC = CreateCompatibleDC(surfaceDC);
// Aquiring of the current time String with my global Helper Method
const char* currentTimeStr = GetCurrentTimeStr();
// Preparing of the HDC
SetBkColor(memDC, 0xff000000);
SetBkMode(memDC, TRANSPARENT);
SetTextAlign(memDC, TA_TOP | TA_LEFT);
SetTextColor(memDC, GUI_FONT_COLOR_Y);
// Draw a the time to the surface
ExtTextOut(memDC, 0, 0, ETO_CLIPPED, NULL, currentTimeStr, strlen(currentTimeStr), NULL);
// Free resources for the mem DC
DeleteDC(memDC);
}
遗憾的是,截取的 ScreenShot.bmp 仅包含游戏的捕获,但其中没有其他文本。
我哪里做错了?
【问题讨论】:
标签: c++ winapi directx direct3d directx-9