我正在显示我的应用程序的fps。当我改变文本的大小或位置时,有时候它没有正确呈现,布局矩形也足够大。
任何人都知道如何解决这个问题?
示例代码,仅限片段:
变量:
IDWriteTextFormat* textFormat;
WCHAR* text = L"Example0101";
int textSize = (int)wcslen(text);
D2D1_RECT_F rect = {};
ID2D1SolidColorBrush* brush;
构造
Game::Game(ID2D1HwndRenderTarget* D2DRenderTarget) {
this->D2DRenderTarget = D2DRenderTarget;
CoInitialize(NULL);
CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&WICImagingFactory);
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), (IUnknown**)&writeFactory);
writeFactory->CreateTextFormat(
L"Arial",
NULL,
DWRITE_FONT_WEIGHT_REGULAR,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
16.0f,
L"en-us",
&textFormat
);
rect.left = 480.0f;
rect.top = 275.0f;
rect.right = 1000.0f;
rect.bottom = 1000.0f;
D2DRenderTarget->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &brush);
}
图:
void Game::draw() {
D2DRenderTarget->Clear(D2D1::ColorF(0.5f, 0.5f, 0.9f, 1.0f));
D2DRenderTarget->DrawTextW(text, textSize, textFormat, rect, brush, D2D1_DRAW_TEXT_OPTIONS_NO_SNAP, DWRITE_MEASURING_MODE_GDI_CLASSIC);
}
的RenderTarget:
D2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
window,
D2D1::SizeU(960, 540),
D2D1_PRESENT_OPTIONS_IMMEDIATELY),
&D2DRenderTarget
);
一切都很正常。我想这可以通过某种平滑来解决,或者我只是忘了一些东西。