gpt4 book ai didi

C++ D3D9 Alpha 与 Creators Update 融合

转载 作者:行者123 更新时间:2023-11-30 05:14:02 27 4
gpt4 key购买 nike

目前我正在开发一个使用 dx9 创建叠加层的应用程序。现在我遇到了一个问题,自从我将 Windows 10 升级到最新版本(Creators Update)后,它无法使用 alpha channel 例如。如果我试图渲染一个透明的矩形,它总是保持 100% 可见

Setup

WNDCLASSEX wc = {
sizeof(WNDCLASSEX),
0,
WndProc,
0,
0,
nullptr,
LoadIcon(nullptr, IDI_APPLICATION),
LoadCursor(nullptr, IDC_ARROW),
nullptr,
nullptr,
OverlayName.c_str(),
LoadIcon(nullptr, IDI_APPLICATION)
};

if (!RegisterClassEx(&wc))
return false;

m_hWndOverlay = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED,
OverlayName.c_str(),
OverlayName.c_str(),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr, nullptr, nullptr, nullptr);

if (!m_hWndOverlay)
return false;

if (!SetLayeredWindowAttributes(m_hWndOverlay, RGB(NULL, NULL, NULL), 255, ULW_COLORKEY | LWA_ALPHA))
return false;

static MARGINS DWMMargins = { -1, -1, -1, -1 };
if (!HR(DwmExtendFrameIntoClientArea(m_hWndOverlay, &DWMMargins), "DwmExtendFrameIntoClientArea()"))
return false;

ShowWindow(m_hWndOverlay, SW_SHOWDEFAULT);
if (!UpdateWindow(m_hWndOverlay))
return false;

if (!HR(Direct3DCreate9Ex(D3D_SDK_VERSION, &m_pDirect3D9Ex), "Direct3DCreate9Ex()"))
return false;

D3DPRESENT_PARAMETERS params;
ZeroMemory(&params, sizeof(D3DPRESENT_PARAMETERS));

params.Windowed = TRUE;
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
params.BackBufferFormat = D3DFMT_A8R8G8B8;
params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D16;
params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.PresentationInterval = 0x80000000L;
DWORD dwMSQAAQuality = 0;

if (HR(m_pDirect3D9Ex->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, true, D3DMULTISAMPLE_NONMASKABLE, &dwMSQAAQuality), "CheckDeviceMultiSampleType()"))
{
params.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
params.MultiSampleQuality = dwMSQAAQuality - 1;
}

if (!HR(m_pDirect3D9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWndOverlay, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, nullptr, &m_pDirect3D9Device), "CreateDeviceEx()"))
return false;

Render Method

void DrawFilledRect(float x, float y, float w, float h, DWORD color) const
{
VERTEX_2D_DIF V[4];

V[0].color = V[1].color = V[2].color = V[3].color = color;

V[0].z = V[1].z = V[2].z = V[3].z = 0;
V[0].rhw = V[1].rhw = V[2].rhw = V[3].rhw = 1;

V[0].x = x;
V[0].y = y;
V[1].x = x + w;
V[1].y = y;
V[2].x = x + w;
V[2].y = y + h;
V[3].x = x;
V[3].y = y + h;

m_pDirect3D9Device->SetFVF(VERTEX_2D_DIF::FVF);
m_pDirect3D9Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &V, sizeof(VERTEX_2D_DIF));
}

Function Call

DrawFilledRect(25.f, 25.f, 25.f, 25.f, 0x10FFFFFF);

有什么建议吗?它在更新之前运行良好...

最佳答案

现在我自己找到了解决方案。

我必须删除 ULW_COLORKEY 选项,该选项旨在使用 crkey 作为透明颜色。这可能不适用于最新的创作者更新。

关于C++ D3D9 Alpha 与 Creators Update 融合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43615946/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com