Skip to content

Jittering Font Rendering when scaling with ImGui::SetWindowFontScale #7924

Description

@corgifist

Version/Branch of Dear ImGui:

Version 1.90.6, Branch: docking

Back-ends:

imgui_impl_opengl.cpp + imgui_impl_glfw3.cpp

Compiler, OS:

Windows 10 64-Bit + MinGW G++ 14.1.0

Full config/build information:

Dear ImGui 1.90.6 (19060)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: _WIN32
define: _WIN64
define: __MINGW32__
define: __MINGW64__
define: __GNUC__=14
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------

io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00008441
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
 DpiEnableScaleFonts
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C06
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasViewports
--------------------------------

io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 2048,4096
io.DisplaySize: 1920.00,1017.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 12.00,12.00
style.WindowBorderSize: 1.00
style.FramePadding: 8.00,3.00
style.FrameRounding: 2.00
style.FrameBorderSize: 1.00
style.ItemSpacing: 4.00,6.00
style.ItemInnerSpacing: 6.00,6.00

Details:

My Issue/Question:

Hello! Currently I'm having two fonts loaded in my application:

  • One font with 16.0f with RasterizerDensity set to 1 (the default value)
  • One font with 16.0f but with RasterizerDensity set to 5 (I'm using thedmd's node editor, so I'm using this ultra-dense font as a workaround for zooming

I noticed that when using ImGui::SetWindowFontScale(1.5f); the baseline of the font becomes wrong and it results in the rendered text being jittery.

I'm loading fonts using the io.Fonts->AddFontFromMemoryCompressedTTF() with cyrillic glyph ranges included and disabled PixelSnapH

Screenshots/Video:

I made a little comparasion between different SetWindowFontScale values:
(In the screensots below I was using the font with RasterizerDensity set to 5)
(The test pharse is Attribute | Blending | Easing because you can clearly see the jittering with it)

  • 1.4 font scale, no jittering spotted
    image

  • 1.5 font scale, the peak jitteriness
    image

  • 1.6 font scale, for some reasons one letters seem to be narrower than others (like the seccond t in Attribute)
    image

  • 1.7 font scale, jittering disappears
    image

When using font scale bigger than 1.7 the jittering disappears completely and the text looks normal as it should look
image

Minimal, Complete and Verifiable Example code:

ImGui::Begin("Text Jittering");

ImFontConfig fontCfg = {};
fontCfg.RasterizerDensity = 5;

auto someVeryDenseFont = io.Fonts->AddFontFromMemoryCompressedTTF(
                    s_someFontBytes, s_someFontSize,
                    16.0f, &fontCfg, io.Fonts->GetGlyphRangesCyrillic());


ImGui::PushFont(someVeryDenseFont);
ImGui::SetWindowFontScale(1.5f);
ImGui::Text("Blending | Attribute | Easing");
ImGui::SetWindowFontScale(1.0f);
ImGui::PopFont();

ImGui::End();

(EDIT: Fixed some typo in MCVE)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions