ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.51k stars 10.14k forks source link

Font Awesome 6 is blurry in any size bigger than 13.f #6148

Closed cuk0r closed 1 year ago

cuk0r commented 1 year ago

Version/Branch of Dear ImGui:

Version: 1.89.2 Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp + imgui_impl_win32.cpp Compiler: MSVC Operating System: Windows 10

My Issue/Question:

I try to render Font Awesome 6 Pro icons using a ImDrawList, and its only drawn sharp if I use 13.f font size. Other font sizes are extremely blurry, even with adjusted font sizes.

Screenshots/Video

kép

Standalone, minimal, complete and verifiable example:

//Loading
ImFontConfig awesome_cfg{};
awesome_cfg.MergeMode = true;
awesome_cfg.GlyphMinAdvanceX = 100.0f;
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFont* m_awesome = ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 100.f, &awesome_cfg, icon_ranges);

//Drawing
dl->AddText(m_awesome, 100.f, ImVec2(pos.x, pos.y), IM_COL32(255, 255, 255, 255), ICON_FA_FEATHER);
ocornut commented 1 year ago

Have you tried with imgui_freetype?

cuk0r commented 1 year ago

I added imgui_freetype and builded successfully. I tried to use it with adding this to the load config.

awesome_cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags::ImGuiFreeTypeBuilderFlags_ForceAutoHint;

It didn't change anything.

cuk0r commented 1 year ago

Actually I got it working, if anyone has this same exact issue, disabling merge mode was the way to go. It now renders sharp and nice icons :)

ocornut commented 1 year ago

This seems odd. MergeMode shouldn't affect the rendered glyphs, and it is difficult to use an icon font without merging them. Which font setting did you use for the font you merged on?

cuk0r commented 1 year ago

Yes I was thinking about why it would cause an issue. Right now I load the font like this.

ImFontConfig awesome_cfg{};
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
ImFont* m_awesome = ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/fa-solid-900.ttf", 100.f, &awesome_cfg, icon_ranges);
ocornut commented 1 year ago

Note our current font system is rather poor and rendering at 100.0f you'll likely want to set OversamplingH to 1 in the ImFontConfig structure to save on memory and rendering time. https://github.com/ocornut/imgui/blob/master/docs/FONTS.md