How can I load a font after creating tgui::Font?

Started by GetterSetter, 27 March 2024, 17:49:51


Hello, I want to load the font after creating tgui::Font object, but I looked through the documentation and there are no such functions as loadFromFile() or loadFromMemory(). So I decided to do the following:
tgui::Font font;
but this leads to a segmentation fault. Are there any ways to do what I intend to do?


You can just create a new font object:
Code (cpp) Select
tgui::Font font;
font = tgui::Font("font.ttf");

There is practically no performance cost in copying the Font object, as it is a lightweight object that will just share its internal resources between the different font objects.

Note that unlike Texture objects, creating multiple Font objects with the same filename will cause the file to be loaded multiple time. So to keep memory usage minimal, you should only call the tgui::Font("font.ttf") constructor once in your code and then just copy that font object to anywhere that you need it.


Okay, thank you for your comprehensive answer!