feat: Added Subpixel Font rendering (#2092)

Proof of concept for implementing subpixel processing in ImGui. This is
work in progress, and it is bound to have problems.

What it does:
1) Uses freetype own subpixel processing implementation to build a
32-bit color atlas for the default font only (no icons, no unifont) . 2)
Avoids pixel perfect font conversion when possible. 3) Self contained,
no ImGui source code changes.
4) Results in much improved legibility of fonts rendered on low dpi LCD
screens that use horizontal RGB pixel layouts (no BRG or OLED or CRT if
they even exist anymore)

What it doesn't:
1) Fancy class based interface. The code is barely the minimum needed to
show it can work. 2) Dual source color blending. That needs to be
implemented in shader code, so it needs to change ImGui source code
although minimally. This will result in some characters appearing dimmer
than others. Easily fixed with small fragment and vertex shaders. 3)
subpixel positioning. If characters are very thin they will look
colored, or they can be moved to improve legibility. 4) deal with
detection of fringe cases including rare pixel layouts, non LCD screens,
Mac-OS not handling subpixel rendering and any other deviation from the
standard LCD. 5) tries to be efficient in speed or memory use. Font
Atlases will be 4 times the size they were before, but there are no
noticeable delays in font loading in the examples I have tried.

Any comments and code improvements are welcome.

---------

Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
paxcut
2025-05-11 06:36:32 -07:00
committed by GitHub
parent 8cd961596e
commit 5c4cf7379f
19 changed files with 510 additions and 94 deletions

View File

@@ -1335,7 +1335,7 @@ namespace hex {
ImGui_ImplOpenGL3_Init();
ImGui_ImplGlfw_InstallEmscriptenCallbacks(m_window, "#canvas");
#else
ImGui_ImplOpenGL3_Init("#version 130");
ImGui_ImplOpenGL3_Init("#version 410");
#endif
ImGui_ImplGlfw_SetCallbacksChainForAllWindows(true);