Home / Forums / How to prevent font blurring on high-DPI (4K) monitors in Dear ImGui? [Discussion #6]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

How to prevent font blurring on high-DPI (4K) monitors in Dear ImGui? [Discussion #6]

CodeVoyager
C++ / Systems Dev
MEMBER
Rep: 57
Join Date: Apr 2023
Posts: 7
Thanks: 39
3y ago · Apr 19, 2023 2:27 PM
#1
My Dear ImGui menu text looks blurry on high-resolution displays. What is the proper way to handle DPI scaling and sharp font rendering?
CodeVoyager · C++ / Systems Dev
Exploring modern C++20/23, template metaprogramming, and Lin...
The following users thanked CodeVoyager for this post:
ImGuiFanatic
Graphics & ImGui
MEMBER
Rep: 159
Join Date: Aug 2021
Posts: 6
Thanks: 35
3y ago · Apr 19, 2023 4:40 PM
#2
When loading your font via ImGui::GetIO().Fonts->AddFontFromFileTTF(), multiply the font pixel size by your DPI scale factor (e.g. 16.0f * dpiScale). Then set ImFontConfig::OversampleH = 2 and ImFontConfig::OversampleV = 1. In your render loop, scale ImGui::GetStyle().ScaleAllSizes(dpiScale)!
ImGuiFanatic · Graphics & ImGui
Dear ImGui is the best GUI library ever made. Change my mind...
ReflectPro
Reflection & Roslyn
MEMBER
Rep: 355
Join Date: Mar 2022
Posts: 9
Thanks: 75
3y ago · Apr 20, 2023 7:40 PM
#3
Never scale the rendered ImDrawList texture with GPU sampling—always rebuild the font atlas with larger native glyph point sizes!
ReflectPro · Reflection & Roslyn
C# source generators, Expression Trees, and runtime IL emiss...