mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Font Atlas Texturesize too big ? #491
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#491
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I added 4 seperate .ttf files to cover all the kinky utf8 characters. It all works nicely, but people running integrated graphics are crashing nicely.
http://pasteboard.co/UMqJv3C.png
If I take out 2 of the files, the texture gets smaller and everything is good. Could that be the reason, that the texture is too large and the little "gpus" cannot deal with it? Do you have any idea how I can work around this ? I'm using the DX9 code.
I tried making 4 x "DefaultLanguage" + add each time one of the .ttf files, so that I would always have the GetGlyphRangesDefault merged with one of the specific languages (Korean / Chines / Russian / Japanese). Sadly I fail to get this to work. Maybe you have a tiny hint how I have to approach this codewise ?
currently I was doing this:
As usual, after asking for help, I found a way to create 4 fonts with default + ttf loaded.
Is it supposed to be done like this ?
'''
io.Fonts->AddFontDefault();
ImFontConfig config;
strcpy(config.Name, "Cyrillic");
config.MergeMode = true;
io.Fonts->AddFontFromFileTTF(..TTF1..), 16.0f, &config, io.Fonts->GetGlyphRangesCyrillic());
ImFontConfig config2;
config2.OversampleH = 1;
config2.OversampleV = 1;
config2.PixelSnapH = true;
config2.MergeMode = false;
strcpy(config2.Name, "");
io.Fonts->AddFontDefault(&config2);
strcpy(config2.Name, "Chinese");
config2.MergeMode = true;
io.Fonts->AddFontFromFileTTF(..TTF2...), 14.0f,&config2,io.Fonts->GetGlyphRangesChinese());
'''
...
My initial question regarding the very large texture + crash still stands, :)
I think this has been asked before, its because every glyph from the ttf is added, and there are a LOT in there. Some way of picking the used glyphs or something is probably the only way to solve it while still using the same ttf file I think.
well, I guess I'll go with an not so nice language selector then, thanks for the reply !
I love that project :)
There's a few things involved.
A) First, integrated graphics drivers have limit on texture size on each axis. ImGui default to a 2048 pixel wide texture here. You can do
Fonts.TexDesiredWidth = 8096;to manually set the texture width and then the height will be reduced and it may just work.Perhaps we should tweak this section of the code in imgui_draw.cpp to further increase the default width is not specified:
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.B) As you pointed out, reducing the amount of Oversampling will also get you smaller textures.
C) If you are running a game with known script the best solution is probably to compute your glyph ranges based on what you script actually uses, because most of those Chinese characters will be very unlikely used.
D) ImGui needs a way ot dynamically filling the font atlas, it's been in my todo list for a while but isn't a top priority. It's not an hard task but it needs to be done in a very careful and precise manner to not hurt performances as text size calculation is a known bottleneck.
Thanks for the response!
:)
Big chinese font problem solved.
Hi just wondering if there is a limit on the number of fonts per atlas?
Trying to get a drop down list or similar of all the fonts in the system font directory and when each is clicked a small sample bit of text is displayed.
It seems to "work" except fa.GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_pp); returns no data.
If I try with "ar*.ttf" it works fine and the texture is quite small.
Other thing I was thinking was one of the loaded TTF's is the cause and not necessarily the number of fonts.
My test code is below....
[code]
[/code]
Update : Not too sure if it's a bug or not....
It seems if you load a font with a range ... say the text "12345" (like above) and the font is loaded but that range is not in the actual font the pixel build fails. I took out the range bit and it seems quite happy chugging out 20 full fonts into the bitmap. (see screen capture). However it got upset with a small build where a font was missing the range of desired characters.
The question is I guess... should this stop the font being built as usually fallback characters are utilized.... or do I have to make sure it includes these fallback characters in the range?

Other than that though... getting more and more impressed by ImGui. Got custom icons working well and even have so when used in a radio button group the unselected ones are grayscale.
For solution (that fixed it for me) see https://github.com/nothings/stb/issues/1086