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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

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

TypeSystemNerd
Type Theory & CLR
MEMBER
Rep: 314
Join Date: Nov 2024
Posts: 6
Thanks: 57
2y ago · Oct 1, 2023 11:09 AM
#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?
TypeSystemNerd · Type Theory & CLR
Covariance, contravariance, struct boxing, and value type se...
The following users thanked TypeSystemNerd for this post:
HexRays99
Senior Reverse Engineer
VIP
Rep: 380
Join Date: Apr 2022
Posts: 36
Thanks: 94
2y ago · Oct 1, 2023 12:30 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)!
HexRays99 · Reverse Engineering & Static Analysis
CPP
// Always check your pointers!
if (!pLocalPlayer) return;
ZeroMemory
Member
MEMBER
Rep: 75
Join Date: Oct 2024
Posts: 32
Thanks: 18
2y ago · Oct 2, 2023 2:30 PM
#3
Never scale the rendered ImDrawList texture with GPU sampling—always rebuild the font atlas with larger native glyph point sizes!
ZeroMemory · Always experimenting