Home > Mobile >  Why does direct2d look pixelated and inaccurate?
Why does direct2d look pixelated and inaccurate?

Time:12-20

I created a layered window and added some rounded rectangles, ellipses and text to make a custom window.

This is in short how I wrote it:


D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory);

d2dFactory->CreateHwndRenderTarget
    (
        RenderTargetProperties(),
        HwndRenderTargetProperties(hwnd, SizeU(clientRect.right, clientRect.bottom)),
        &pRenderTarget
    );

...

DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(dWriteFactory), reinterpret_cast<IUnknown**>(&dWriteFactory));

dWriteFactory->CreateTextFormat
    (
        L"Calibri",
        NULL,
        DWRITE_FONT_WEIGHT_NORMAL,
        DWRITE_FONT_STYLE_NORMAL,
        DWRITE_FONT_STRETCH_NORMAL,
        14.0f,
        L"en-us",
        &pTextFormat
    );

...

D2D1_ROUNDED_RECT roundedRect = RoundedRect
    (
        RectF
        (
            clientRect.left,
            clientRect.top,
            clientRect.right,
            clientRect.bottom
        ),
        20, 20
    );

...

pRenderTarget->BeginDraw();

...

pRenderTarget->FillRoundedRectangle
    (
        roundedRect,
        SCB_DARK_BLUE
    );

pRenderTarget->DrawTextA
    (
        title,
        titleSize,
        pTextFormat,
        RectF(185, 2, 255, 2),
        SCB_WHITE
    );

pRenderTarget->FillEllipse
    (
        Ellipse
        (
            Point2F(20, 10),
            6, 6
        ),
        SCB_RED
    );

I followed Microsoft's documentation.

The window looks like this

Its size in pixels is 300 by 400. The text, corners and ellipses look pixelated and inaccurate.

What am I missing in my program? Thanks in advance.

CodePudding user response:

Is your program set to be high DPI aware? Note that I am blind and therefore can't see your screenshot but that is the first thing I think of from your description.

If using visual studio go to project->properties then Manifest tool -> Input and Output and check the "DPI awareness" setting. It should be either "High DPI Aware" or "Per Monitor High DPI Aware".

  • Related