From 0abe668221b65e376aeabd39be52d049f0df3b1d Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 11 Sep 2015 16:50:00 +0100 Subject: [PATCH] ImFontAtlas: Added TexDesiredWidth and tweaked default cheapo best-width choice(#327) --- imgui.h | 5 +++-- imgui_demo.cpp | 3 +-- imgui_draw.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/imgui.h b/imgui.h index 722b38c1..160941d4 100644 --- a/imgui.h +++ b/imgui.h @@ -1230,8 +1230,9 @@ struct ImFontAtlas void* TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It ia passed back to you during rendering. unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4 - int TexWidth; - int TexHeight; + 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. ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block) ImVector Fonts; diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 69c2dad1..ba8b8d78 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -206,9 +206,8 @@ void ImGui::ShowTestWindow(bool* opened) { ImGui::TextWrapped("Tip: Load fonts with io.Fonts->AddFontFromFileTTF()."); ImFontAtlas* atlas = ImGui::GetIO().Fonts; - if (ImGui::TreeNode("Atlas texture")) + if (ImGui::TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) { - ImGui::Text("%dx%d pixels", atlas->TexWidth, atlas->TexHeight); ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128)); ImGui::TreePop(); } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 7ba0bf1a..2c053f9c 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -954,7 +954,7 @@ ImFontAtlas::ImFontAtlas() TexID = NULL; TexPixelsAlpha8 = NULL; TexPixelsRGBA32 = NULL; - TexWidth = TexHeight = 0; + TexWidth = TexHeight = TexDesiredWidth = 0; TexUvWhitePixel = ImVec2(0, 0); } @@ -1195,7 +1195,7 @@ bool ImFontAtlas::Build() } // Start packing - TexWidth = (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters. + TexWidth = (TexDesiredWidth > 0) ? TexDesiredWidth : (total_glyph_count > 2000) ? 2048 : (total_glyph_count > 1000) ? 1024 : 512; // Width doesn't actually matters much but some API/GPU have texture size limitations, and increasing width can decrease height. TexHeight = 0; const int max_tex_height = 1024*32; stbtt_pack_context spc;