我有一个正在进行的项目,该项目利用DirectX 11在外部窗口上覆盖文本(不注入任何内容或使用任何类型的内部API挂钩)。我正在创建一个透明窗口,并使用FW1FontWrapper处理实际的文本绘图。我遇到的问题是文本上有伪影,并且看起来失真,具体取决于我绘制的窗口的当前颜色。窗口为浅色时,将导致文本基本上不可读,而在深色背景/窗口上绘制将使其看起来大部分正常。
有关我在说什么的示例,请参见以下两个图像(分别在深色和浅色窗口上显示文字):
我的猜测是问题出在Direct X初始化代码中。要么混合,要么混合跨文本和基础窗口的Alpha通道。我的直接X实现在初始化期间使用以下代码:
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
DXGI_SWAP_CHAIN_DESC scd;
// clear out the struct for use
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
// fill the swap chain description struct
scd.BufferCount = 1; // one back buffer
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // use 32-bit color
scd.BufferDesc.Width = ScreenWidth; // set the back buffer width
scd.BufferDesc.Height = ScreenHeight; // set the back buffer height
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how swap chain is to be used
scd.OutputWindow = handleWindow; // the window to be used
scd.SampleDesc.Count = 1; // how many multisamples
scd.Windowed = TRUE;
scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // allow full-screen switching
D3D_FEATURE_LEVEL FeatureLevelsSupported;
// create a device, device context and swap chain using the information in the scd struct
D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
0,
&featureLevel,
1,
D3D11_SDK_VERSION,
&scd,
&m_pSwapchain,
&m_pDevice,
&FeatureLevelsSupported,
&m_pContext);
// get the address of the back buffer
ID3D11Texture2D *pBackBuffer;
m_pSwapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
// use the back buffer address to create the render target
m_pDevice->CreateRenderTargetView(pBackBuffer, NULL, &m_pBackBuffer);
pBackBuffer->Release();
// set the render target as the back buffer
m_pContext->OMSetRenderTargets(1, &m_pBackBuffer, NULL);
// Set the viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.MinDepth = 0;
viewport.MaxDepth = 1;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = ScreenWidth;
viewport.Height = ScreenHeight;
m_pContext->RSSetViewports(1, &viewport);
FW1FontWrapper使用所有默认参数初始化。
我希望在这方面有更多经验的人会注意到这里出了什么问题,或者至少可以指出正确的方向。我花了无尽的时间试图找到解决方案。如果可以使事情更清楚,我将提供任何其他信息或代码。