1

我正在显示我的应用程序的 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);
}

渲染目标:

D2DFactory->CreateHwndRenderTarget(
    D2D1::RenderTargetProperties(),
    D2D1::HwndRenderTargetProperties(
        window,
        D2D1::SizeU(960, 540),
        D2D1_PRESENT_OPTIONS_IMMEDIATELY),
    &D2DRenderTarget
);

再看一张照片

一切都很正常。我想这可以通过某种平滑来解决,或者我只是忘记了一些东西。

4

0 回答 0