ImFontAtlas: heuristic increase texture width up to 4096 with 4000+ glyphs. Various comments (#491)

This commit is contained in:
ocornut
2016-01-20 10:30:28 +00:00
parent 3922988dea
commit e585204d82
3 changed files with 15 additions and 6 deletions

View File

@ -2,6 +2,8 @@
The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' that you can use without any external files.
Those are only provided as a convenience, you can load your own .TTF files.
Fonts are rasterized in a single texture at the time of calling either of io.Fonts.GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build().
---------------------------------
LOADING INSTRUCTIONS
---------------------------------
@ -20,10 +22,17 @@
ImFontConfig config;
config.OversampleH = 3;
config.OversampleV = 3;
config.OversampleV = 1;
config.GlyphExtraSpacing.x = 1.0f;
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config);
If you have very large number of glyphs or multiple fonts:
- Mind the fact that some graphics drivers have texture size limitation.
- Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function).
- You may reduce oversampling, e.g. config.OversampleH = 2 or 1.
- Reduce glyphs ranges, consider calculating them based on your source data if this is possible.
Combine two fonts into one:
// Load main font