How to load io.Fonts as a global? Or some other means to prevent loading fonts multiple times, once per graphics context? #7080
Replies: 4 comments
-
I'm struggling a bit to understand what you're doing exactly. By definition, the ImGui's Are you shutting down the whole of ImGui by calling See Lines 290 to 297 in b112d73 |
Beta Was this translation helpful? Give feedback.
-
Thank you for the help! I misread what you said at first because I neglected to read that code comment like you asked me to. After reading the code comment and understanding what you meant that fixed the issue for me when I did as you said. Thank you a ton!! :D |
Beta Was this translation helpful? Give feedback.
-
You can also create a ImFontAtlas manually and pass it to CreateContext() and then the context doesn’t own the font atlas so it can be used accross multiple contexts regardless of their lifetime. |
Beta Was this translation helpful? Give feedback.
-
@ocornut Thank you! That is what I am doing in my code now as suggested by @nicolasnoble also, and it is working great: |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this question falls under the category of a discussion you would delete or not so forgive me if this doesn't belong here. I am not having issue with loading fonts but I am in fact having issue related to the process there of.
I would like My io.Fonts to be loaded only once for an application instance, instead of loading the fonts from scratch all over again every time I create a new window with an Imgui rendering context attached (within the same running application instance).
For example, I have a dialog I create, in this case an SDL window, it loads all the fonts it needs, but I only want it to do that once at either application launch or the first time that SDL window is created with the ImGui context attached, instead of needing to reload all the font files necessary to have full UTF-8 support every time a new one of these dialogs open, which loading this many font files in particular is very slow, especially when including fonts like Chinese Traditional/Simplified/Hongkong or Japanese to the mix on top of all the other characters needed to support the entire UTF-8 character set.
The goal here is only load the fonts once per process instance, so only the first time opening the dialog will take a while, not taking that long anymore for other times opening the dialog in the app instance there after.
Here's my relevant project and where I am attempting to load fonts:
https://github.com/time-killer-games/libfiledialogs/blob/052b053b1996d068961c1019a8e2f6aaf8ebcc78/filedialogs/filedialogs.cpp#L296-L305
I thought making the
io
variable a static local or global would help, but then the dialogs drew their content incorrectly, so I'm not sure what the proper workaround to this would be.Also if this issue doesn't belong here, before deleting it, please let me know a way to contact you guys which would be a more acceptable place to discuss this sort of thing.
Thank you!
Samuel Venable
Beta Was this translation helpful? Give feedback.
All reactions