Skip to content

Commit 21828b0

Browse files
committed
ImFontAtlas: Rewrote FreeType based builder.
- Fixed abnormally high atlas height. (#618) - Fixed support for any values of TexGlyphPadding (not just only 1). (#618) - Atlas width is now properly based on total surface rather than glyph count (unless overridden with TexDesiredWidth). (#618) - Fixed atlas builder so missing glyphs won't influence the atlas texture width. (#2233, #618) - Fixed atlas builder so duplicate glyphs (when merging fonts) won't be included in the rasterized atlas. (#618)
1 parent 9a97128 commit 21828b0

File tree

3 files changed

+399
-194
lines changed

3 files changed

+399
-194
lines changed

docs/CHANGELOG.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ Other Changes:
7272
Missing calls to End(), past the assert, should not lead to crashes or to the fallback Debug window appearing on screen.
7373
Those changes makes it easier to integrate dear imgui with a scripting language allowing, given asserts are redirected
7474
into e.g. an error log and stopping the script execution.
75-
- ImFontAtlas: Stb: Atlas width is now properly based on total surface rather than glyph count (unless overridden with TexDesiredWidth).
76-
- ImFontAtlas: Stb: Fixed atlas builder so missing glyphs won't influence the atlas texture width. (#2233)
77-
- ImFontAtlas: Stb: Fixed atlas builder so duplicate glyphs (when merging fonts) won't be included in the rasterized atlas.
75+
- ImFontAtlas: Stb and FreeType: Atlas width is now properly based on total surface rather than glyph count (unless overridden with TexDesiredWidth).
76+
- ImFontAtlas: Stb and FreeType: Fixed atlas builder so missing glyphs won't influence the atlas texture width. (#2233)
77+
- ImFontAtlas: Stb and FreeType: Fixed atlas builder so duplicate glyphs (when merging fonts) won't be included in the rasterized atlas.
78+
- ImFontAtlas: FreeType: Fixed abnormally high atlas height.
79+
- ImFontAtlas: FreeType: Fixed support for any values of TexGlyphPadding (not just only 1).
7880
- ImDrawList: Optimized some of the functions for performance of debug builds where non-inline function call cost are non-negligible.
7981
(Our test UI scene on VS2015 Debug Win64 with /RTC1 went ~5.9 ms -> ~4.9 ms. In Release same scene stays at ~0.3 ms.)
8082
- IO: Added BackendPlatformUserData, BackendRendererUserData, BackendLanguageUserData void* for storage use by back-ends.

misc/freetype/README.md

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# imgui_freetype
22

3-
This is an attempt to replace stb_truetype (the default imgui's font rasterizer) with FreeType.
4-
Currently not optimal and probably has some limitations or bugs.
5-
By [Vuhdo](https://github.com/Vuhdo) (Aleksei Skriabin). Improvements by @mikesart. Maintained by @ocornut.
3+
Build font atlases using FreeType instead of stb_truetype (the default imgui's font rasterizer).
4+
<br>by @vuhdo, @mikesart, @ocornut.
65

7-
**Usage**
8-
1. Get latest FreeType binaries or build yourself.
6+
### Usage
7+
8+
1. Get latest FreeType binaries or build yourself (under Windows you may use vcpkg with `vcpkg install freetype`).
99
2. Add imgui_freetype.h/cpp alongside your imgui sources.
1010
3. Include imgui_freetype.h after imgui.h.
11-
4. Call ImGuiFreeType::BuildFontAtlas() *BEFORE* calling ImFontAtlas::GetTexDataAsRGBA32() or ImFontAtlas::Build() (so normal Build() won't be called):
11+
4. Call `ImGuiFreeType::BuildFontAtlas()` *BEFORE* calling `ImFontAtlas::GetTexDataAsRGBA32()` or `ImFontAtlas::Build()` (so normal Build() won't be called):
1212

1313
```cpp
1414
// See ImGuiFreeType::RasterizationFlags
@@ -17,13 +17,14 @@ ImGuiFreeType::BuildFontAtlas(io.Fonts, flags);
1717
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
1818
```
1919
20-
**Gamma Correct Blending**
20+
### Gamma Correct Blending
21+
2122
FreeType assumes blending in linear space rather than gamma space.
2223
See FreeType note for [FT_Render_Glyph](https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph).
2324
For correct results you need to be using sRGB and convert to linear space in the pixel shader output.
2425
The default imgui styles will be impacted by this change (alpha values will need tweaking).
2526
26-
**Test code Usage**
27+
### Test code Usage
2728
```cpp
2829
#include "misc/freetype/imgui_freetype.h"
2930
#include "misc/freetype/imgui_freetype.cpp"
@@ -42,16 +43,15 @@ while (true)
4243
if (freetype_test.UpdateRebuild())
4344
{
4445
// REUPLOAD FONT TEXTURE TO GPU
45-
// e.g ImGui_ImplGlfwGL3_InvalidateDeviceObjects() + ImGui_ImplGlfwGL3_CreateDeviceObjects()
46+
// e.g ImGui_ImplOpenGL3_DestroyDeviceObjects() + ImGui_ImplOpenGL3_CreateDeviceObjects()
4647
}
4748
ImGui::NewFrame();
4849
freetype_test.ShowFreetypeOptionsWindow();
4950
...
50-
}
5151
}
5252
```
5353

54-
**Test code**
54+
### Test code
5555
```cpp
5656
#include "misc/freetype/imgui_freetype.h"
5757
#include "misc/freetype/imgui_freetype.cpp"
@@ -61,7 +61,7 @@ struct FreeTypeTest
6161
enum FontBuildMode
6262
{
6363
FontBuildMode_FreeType,
64-
FontBuildMode_Stb,
64+
FontBuildMode_Stb
6565
};
6666

6767
FontBuildMode BuildMode;
@@ -120,14 +120,7 @@ struct FreeTypeTest
120120
};
121121
```
122122
123-
**Known issues**
124-
- Output texture has excessive resolution (lots of vertical waste).
123+
### Known issues
125124
- FreeType's memory allocator is not overridden.
126125
- `cfg.OversampleH`, `OversampleV` are ignored (but perhaps not so necessary with this rasterizer).
127126
128-
**Obligatory comparison screenshots**
129-
130-
Using Windows built-in segoeui.ttf font. Open in new browser tabs, view at 1080p+.
131-
132-
![freetype rasterizer](https://raw.githubusercontent.com/wiki/ocornut/imgui_club/images/freetype_20170817.png)
133-

0 commit comments

Comments
 (0)