I'm displaying the fps of my application. When I change the size or position of the text, it sometimes isn't rendered properly and the layout rect is big enough.
Anyone know how to fix this?
Example code, only snippets:
Variables:
IDWriteTextFormat* textFormat;
WCHAR* text = L"Example0101";
int textSize = (int)wcslen(text);
D2D1_RECT_F rect = {};
ID2D1SolidColorBrush* brush;
Constructor:
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);
}
Drawing:
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
);
Everything is very normal. I guess this is solved with some kind of smoothing or maybe I just forgot something.