From 582900a1b9198bc941d139b0374b92a178c27efe Mon Sep 17 00:00:00 2001 From: quarrel07 <178681861+quarrel07@users.noreply.github.com> Date: Sun, 19 Jul 2026 07:12:17 -0700 Subject: [PATCH] macOS: sharp ImGui menu text on Retina at every menu scale (#714) * macOS: sharp ImGui menu text on Retina at every menu scale On a HiDPI display the ImGui overlay renders into a 2x framebuffer, but the glyph atlas is rasterized at the logical point size and stretched up by DisplayFramebufferScale, so all menu text looks fuzzy. Set ImFontConfig::RasterizerDensity on the game fonts and the merged FontAwesome icons: glyphs rasterize at higher resolution without changing logical size or layout. Baked at retinaScale (2.0) times the Menu Scale slider's maximum (2.0) so the runtime FontGlobalScale only ever downsamples a high-res atlas instead of stretching a low-res one, keeping text crisp at every Menu Scale setting. Standard-DPI displays just get a supersampled atlas (identical layout, slightly sharper). Co-Authored-By: Claude Fable 5 * Shorten the RasterizerDensity comment Co-Authored-By: Claude Fable 5 --------- Co-authored-by: Claude Fable 5 --- src/port/Engine.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 5120c82a2..3d516130e 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -587,11 +587,21 @@ uint8_t GameEngine::GetBankIdByName(const std::string& name) { ImFont* GameEngine::CreateFontWithSize(float size, std::string fontPath) { auto mImGuiIo = &ImGui::GetIO(); ImFont* font; + // Rasterize the glyph atlas at higher density so menu text stays sharp on HiDPI/Retina + // displays. Bake at retinaScale * maxMenuScale so the runtime Menu Scale setting + // (FontGlobalScale) only ever downsamples the atlas rather than stretching it blurry. + float rasterDensity = 1.0f; +#if defined(__APPLE__) + constexpr float kRetinaScale = 2.0f; // Retina backing scale + constexpr float kMaxMenuScale = 2.0f; // keep in sync with the gSettings.Menu.Scale slider Max + rasterDensity = kRetinaScale * kMaxMenuScale; +#endif if (fontPath == "") { ImFontConfig fontCfg = ImFontConfig(); fontCfg.OversampleH = fontCfg.OversampleV = 1; fontCfg.PixelSnapH = true; fontCfg.SizePixels = size; + fontCfg.RasterizerDensity = rasterDensity; font = mImGuiIo->Fonts->AddFontDefault(&fontCfg); } else { auto initData = std::make_shared(); @@ -603,7 +613,9 @@ ImFont* GameEngine::CreateFontWithSize(float size, std::string fontPath) { Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fontPath, false, initData)); char* fontDataPtr = (char*) malloc(fontData->DataSize); memcpy(fontDataPtr, fontData->Data, fontData->DataSize); - font = mImGuiIo->Fonts->AddFontFromMemoryTTF(fontDataPtr, fontData->DataSize, size); + ImFontConfig fontCfg = ImFontConfig(); + fontCfg.RasterizerDensity = rasterDensity; + font = mImGuiIo->Fonts->AddFontFromMemoryTTF(fontDataPtr, fontData->DataSize, size, &fontCfg); } // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly float iconFontSize = size * 2.0f / 3.0f; @@ -612,6 +624,7 @@ ImFont* GameEngine::CreateFontWithSize(float size, std::string fontPath) { iconsConfig.MergeMode = true; iconsConfig.PixelSnapH = true; iconsConfig.GlyphMinAdvanceX = iconFontSize; + iconsConfig.RasterizerDensity = rasterDensity; mImGuiIo->Fonts->AddFontFromMemoryCompressedBase85TTF(fontawesome_compressed_data_base85, iconFontSize, &iconsConfig, sIconsRanges); return font;