mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 15:57:03 -05:00
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>
32 lines
1021 B
C++
32 lines
1021 B
C++
#include <hex/api/imhex_api.hpp>
|
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <fonts/vscode_icons.hpp>
|
|
#include <fonts/blender_icons.hpp>
|
|
|
|
namespace hex::fonts {
|
|
|
|
void registerFonts() {
|
|
using namespace ImHexApi::Fonts;
|
|
|
|
/**
|
|
* !!IMPORTANT!!
|
|
* Always load the font files in decreasing size of their glyphs. This will make the rasterize be more
|
|
* efficient when packing the glyphs into the font atlas and therefor make the atlas much smaller.
|
|
*/
|
|
|
|
ImHexApi::Fonts::loadFont("Blender Icons", romfs::get("fonts/blendericons.ttf").span<u8>(),{ { ICON_MIN_BI, ICON_MAX_BI } }, { -1_scaled, -1_scaled });
|
|
|
|
ImHexApi::Fonts::loadFont("VS Codicons", romfs::get("fonts/codicons.ttf").span<u8>(),
|
|
{
|
|
{ ICON_MIN_VS, ICON_MAX_VS }
|
|
},
|
|
{ -1_scaled, -1_scaled });
|
|
|
|
ImHexApi::Fonts::loadFont("Unifont", romfs::get("fonts/unifont.otf").span<u8>(), { }, {}, 0, false, 16);
|
|
}
|
|
|
|
} |