From 718f00d6519a3b0f4bca209749c3a46d6d86451f Mon Sep 17 00:00:00 2001 From: James Wallis <31036241+jadwallis@users.noreply.github.com> Date: Tue, 15 Aug 2017 14:11:04 +0100 Subject: [PATCH 1/2] Make font atlas packing padding configurable --- imgui.h | 1 + imgui_draw.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index 195cdccb..e5f8a614 100644 --- a/imgui.h +++ b/imgui.h @@ -1382,6 +1382,7 @@ struct ImFontAtlas int TexWidth; // Texture width calculated during Build(). int TexHeight; // Texture height calculated during Build(). int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. + int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 3eb8eea6..acae0e20 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1061,6 +1061,7 @@ ImFontAtlas::ImFontAtlas() TexPixelsAlpha8 = NULL; TexPixelsRGBA32 = NULL; TexWidth = TexHeight = TexDesiredWidth = 0; + TexGlyphPadding = 1; TexUvWhitePixel = ImVec2(0, 0); } @@ -1314,13 +1315,13 @@ bool ImFontAtlas::Build() } } - // Start packing. We need a known width for the skyline algorithm. Using a cheap heuristic here to decide of width. User can override TexDesiredWidth if they wish. + // Start packing. We need a known width for the skyline algorithm. Using a cheap heuristic here to decide of width. User can override TexDesiredWidth and TexGlyphPadding if they wish. // After packing is done, width shouldn't matter much, but some API/GPU have texture size limitations and increasing width can decrease height. TexWidth = (TexDesiredWidth > 0) ? TexDesiredWidth : (total_glyph_count > 4000) ? 4096 : (total_glyph_count > 2000) ? 2048 : (total_glyph_count > 1000) ? 1024 : 512; TexHeight = 0; const int max_tex_height = 1024*32; stbtt_pack_context spc; - stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, 1, NULL); + stbtt_PackBegin(&spc, NULL, TexWidth, max_tex_height, 0, TexGlyphPadding, NULL); // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values). ImVector extra_rects; From 9239e91dc9133fa0fa681d0b67db2741de76f17f Mon Sep 17 00:00:00 2001 From: James Wallis <31036241+jadwallis@users.noreply.github.com> Date: Tue, 15 Aug 2017 14:12:32 +0100 Subject: [PATCH 2/2] Whitespace fix to previous --- imgui.h | 2 +- imgui_draw.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index e5f8a614..1f13882f 100644 --- a/imgui.h +++ b/imgui.h @@ -1382,7 +1382,7 @@ struct ImFontAtlas int TexWidth; // Texture width calculated during Build(). int TexHeight; // Texture height calculated during Build(). int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. - int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. + int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index acae0e20..6e94cfb6 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1061,7 +1061,7 @@ ImFontAtlas::ImFontAtlas() TexPixelsAlpha8 = NULL; TexPixelsRGBA32 = NULL; TexWidth = TexHeight = TexDesiredWidth = 0; - TexGlyphPadding = 1; + TexGlyphPadding = 1; TexUvWhitePixel = ImVec2(0, 0); }