我想使用D3D硬件覆盖来叠加和D3D游戏。我正在使用此功能创建叠加层:(source)
HRESULT CreateHWOverlay(HWND hwnd, IDirect3D9Ex *pD3D, IDirect3DDevice9Ex **ppDevice)
{
*ppDevice = NULL;
D3DCAPS9 caps;
ZeroMemory(&caps, sizeof(caps));
HRESULT hr = pD3D->GetDeviceCaps(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
&caps
);
if (FAILED(hr))
{
return hr;
}
// Check if overlay is supported.
if (!(caps.Caps & D3DCAPS_OVERLAY))
{
return D3DERR_UNSUPPORTEDOVERLAY;
}
D3DOVERLAYCAPS overlayCaps = { 0 };
IDirect3DDevice9Ex *pDevice = NULL;
IDirect3D9ExOverlayExtension *pOverlay = NULL;
// Check specific overlay capabilities.
hr = pD3D->QueryInterface(IID_PPV_ARGS(&pOverlay));
if (SUCCEEDED(hr))
{
hr = pOverlay->CheckDeviceOverlayType(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
1920,
1200,
D3DFMT_X8R8G8B8,
NULL,
D3DDISPLAYROTATION_IDENTITY,
&overlayCaps
);
}
// Create the overlay.
if (SUCCEEDED(hr))
{
DWORD flags = D3DCREATE_FPU_PRESERVE |
D3DCREATE_MULTITHREADED |
D3DCREATE_SOFTWARE_VERTEXPROCESSING;
D3DPRESENT_PARAMETERS pp = { 0 };
pp.BackBufferWidth = 1920;//overlayCaps.MaxOverlayDisplayWidth;
pp.BackBufferHeight = 1200;//overlayCaps.MaxOverlayDisplayHeight;
pp.BackBufferFormat = D3DFMT_X8R8G8B8;
pp.SwapEffect = D3DSWAPEFFECT_OVERLAY;
pp.hDeviceWindow = hwnd;
pp.Windowed = TRUE;
pp.Flags = D3DPRESENTFLAG_VIDEO;
pp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
hr = pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
NULL, flags, &pp, NULL, &pDevice);
}
if (SUCCEEDED(hr))
{
(*ppDevice) = pDevice;
(*ppDevice)->AddRef();
}
SafeRelease(&pD3D);
SafeRelease(&pDevice);
SafeRelease(&pOverlay);
return hr;
}
在这里画画:
while(true)
{
//Sleep(10);
D3DRECT rect = {50,50,200,200};
g_pDeviceEx->BeginScene();
RECT r = {0,0,1920,1200};
RECT xrect = {200, 200, 500, 300};
g_Font->DrawTextA(0, "D3D HARDWARE OVERLAY", -1, &xrect, DT_LEFT, D3DCOLOR_ARGB(255,255,0,0));
g_pDeviceEx->Clear(1, &rect, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0,255,0), 50.0,0);
g_pDeviceEx->EndScene();
g_pDeviceEx->PresentEx(&r, &r, hWnd, NULL, 0);
}
当我改变游戏的黑色分辨率时,正在显示叠加层。一旦你看到世界,文字和矩形就消失了。我究竟做错了什么?是的,我正在运行窗口模式。
答案 0 :(得分:3)
该帖子是2个月大,但答案是:
g_pDeviceEx->清除 - >使用颜色(255,0,255,0)擦除后备缓冲区,在BeginScene
之前清除A +