Hello!
I am using freetype-gl in my game development framework
Featherkit. Since I am using C++, I wrap the capabilities of freetype-gl into classes capable of text rendering. This works well, but one issue I had to handle was the issue of texture atlas size. Since it is a library, I cannot know how big atlas the end user needs, and I didn't want to burden the user to choose since it belongs to the inner workings of things. I also cannot use just a really big size, since the user might want multiple different text objects and fonts separate from each other, in which case the memory usage would be huge. The idea I had to solve this was to start out with a small atlas and then let the size grow as needed.
I solved that issue by remembering all texts written to the text object, and if the function texture_font_get_glyph() returns null, it means that the atlas is full. If it is full, then I delete the atlas, and all cached fonts, and then allocate a new atlas with twice the width/height followed by rewriting all text written. This works perfectly and is so far also fast enough for the test cases. There is still one problem however: When the texture_font_get_glyph function fails to allocate a glyph and returns null, it also triggers an fprint to stderr saying "Texture atlas is full (line %d)\n" which of course is undesirable for me since the error is expected and part of how I reallocate the atlas size.
I know that I can use freopen on stderr but that is a bad idea to use in a library since the end user might want to use stderr for own purposes. Is there another solution out there that I can use to get rid of these prints? Or is there a better solution out there for resizing the atlas maybe? Perhaps disabling the error prints could even be made a feature of freetype-gl?
Or what do you guys think? :)
Thanks!