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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

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

SharpShooter_x
Unity C# Modder
MEMBER
Rep: 234
Join Date: May 2024
Posts: 8
Thanks: 29
3y ago · Apr 10, 2023 8:51 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?
SharpShooter_x · Unity C# Modder
Deep diving into Unity script lifecycles, IL2CPP internals, ...
The following users thanked SharpShooter_x for this post:
KernelGamer
C++ / Driver Dev
MEMBER
Rep: 340
Join Date: Sep 2022
Posts: 6
Thanks: 18
3y ago · Apr 10, 2023 11:26 AM
#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)!
KernelGamer · C++ / Driver Dev
Windows Internals, system threads, and high-frequency game l...
ThreadRacer
High Performance C++
VIP
Rep: 71
Join Date: Apr 2023
Posts: 9
Thanks: 17
3y ago · Apr 11, 2023 5:26 PM
#3
Never scale the rendered ImDrawList texture with GPU sampling—always rebuild the font atlas with larger native glyph point sizes!
ThreadRacer · High Performance C++
Lock-free SPSC/MPMC queues, atomic memory orders, and low-la...