【发布时间】:2019-07-30 16:42:15
【问题描述】:
问题截图:
以下是相关的代码位 - 为清楚起见,省略了错误处理等。
D2D1_BITMAP_PROPERTIES1 bp;
bp.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
bp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
bp.dpiX = 96.0f;
bp.dpiY = 96.0f;
bp.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW;
bp.colorContext = nullptr;
...
d2dDeviceContext->SetTarget(targetBitmap);
....
writeFactory->CreateTextFormat(L"Arial", nullptr, DWRITE_FONT_WEIGHT_LIGHT, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 32.0f, L"en-US", &textFormatAccountCreds);
textFormatAccountCreds->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
textFormatAccountCreds->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
std::wostringstream outAccountName;
outAccountName << "Account Name:";
writeFactory->CreateTextLayout(outAccountName.str().c_str(), (UINT32)outAccountName.str().size(), textFormatAccountCreds, (float)800,
(float)600, &textLayoutAccountName);
const float color[4] = { 1.0f, 0.5f, 0.3f, 1.0f };
immediateContext->ClearRenderTargetView(renderTargetView, color);
d2dDeviceContext->BeginDraw();
d2dDeviceContext->DrawTextLayout(D2D1::Point2F(2.0f, 5.0f), textLayoutAccountName, blackBrush);
d2dDeviceContext->EndDraw();
swapChain->Present(0, 0);
正如您在屏幕截图中看到的那样,文本的渲染效果很差——具体来说,第一个“n”似乎在左边被切断了,第一个“u”也是如此,大写的“N”有发生了一些奇怪的混叠。我可以更改文本的大小/位置,呈现的问题会有所不同,但它们仍然存在。
我在这里缺少什么?我已经阅读了 MSDN 上的大多数 DirectWrite 文档,但不清楚我的问题是什么。我确实看到有人提到我应该指定我的文本相对于 dpi 比例的起始位置,但是这个例子非常模糊。
还值得一提的是,我将 Direct3D 和 DirectWrite 与 Direct2D 一起使用,其方式与 this tutorial 中看到的类似。不确定这是否是我的问题。
如果能提供任何帮助,我将不胜感激。非常感谢。
【问题讨论】:
-
如何设置渲染目标大小?窗口宽度(在屏幕截图上)不是 800 有点可疑。
-
这条评论帮助我找到了问题。谢谢!
标签: windows directx direct3d direct2d directwrite