fix: bake UI font atlas at physical DPI size so text isn't skinny on standard-DPI

The font atlas was rasterized once at a fixed 16px and point-filtered, then
scaled to a logical size at draw time. On HiDPI it got upscaled (acceptable);
on standard-DPI it got downscaled, and point filtering dropped rows/columns of
the anti-aliased glyphs, thinning stems into a faint "hyper-skinny" look.

Bake the atlas at the real physical size text is drawn at
(16 * GetUIScale() * GetWindowScaleDPI().y), quantized to 4px steps, and rebuild
it via EnsureUIFont() once per frame when that density changes (resize, or
moving between monitors of different DPI). Use mipmaps + trilinear filtering so
downsampling stays smooth. Call sites are unchanged: DrawTextEx still scales the
atlas glyph to the same logical size, only the backing resolution differs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 18:27:35 -07:00
parent 83277e5086
commit 724956278d
3 changed files with 73 additions and 4 deletions
+10 -4
View File
@@ -779,10 +779,11 @@ int main(int argc, char* argv[])
SearchAndSetResourceDir("resources");
// Load TTF font at a fixed base size. Scaling is handled uniformly by
// GetUIScale() for both layout and DrawTextScaled(), so the font scales
// naturally with the window size on any DPI monitor.
mainFont = LoadFontEx("fonts/DejaVuSansMono.ttf", 16, 0, 0);
// Load the TTF font. The atlas is rasterized at the physical pixel size text
// is actually drawn at (window UI scale * monitor DPI scale) and rebuilt by
// EnsureUIFont() when that density changes, so glyphs stay crisp on both
// HiDPI and standard-DPI displays instead of thinning out when downscaled.
InitUIFont("fonts/DejaVuSansMono.ttf");
if (mainFont.texture.id == 0) {
TraceLog(LOG_WARNING, "Failed to load TTF font, using default bitmap font");
}
@@ -1491,6 +1492,11 @@ int main(int argc, char* argv[])
app.showAbout = false;
}
// Keep the font atlas baked at the current display density (window scale
// * DPI). Cheap no-op unless the density actually changed (resize, or
// dragging the window between monitors of different DPI).
EnsureUIFont();
// Rendering
BeginDrawing();
ClearBackground((Color){ 30, 30, 30, 255 });