SFML community forums

Help => Graphics => Topic started by: tanis on November 24, 2015, 04:20:19 pm

Title: Generating the entire glyphs texture
Post by: tanis on November 24, 2015, 04:20:19 pm
Is there a simple way to tell SFML to generate the entire glyph texture at a certain size when loading the font?
I know the implications, but for the kind of use I have in mind I'm pretty sure the texture would be small enough to fit in memory and it would let me feed the text to a sprite batcher without having to flush it every time a call to render the text is issued.
Thanks in advance!
Title: Re: Generating the entire glyphs texture
Post by: Laurent on November 24, 2015, 04:24:29 pm
const char charset[] = "abcdefg...";
for (auto c : charset)
    font.getGlyph(c, size, false);

Untested, but should be enough.
Title: Re: Generating the entire glyphs texture
Post by: tanis on November 24, 2015, 04:39:12 pm
As dirty as it is but it definitely works well. Thanks!
Title: Re: Generating the entire glyphs texture
Post by: Laurent on November 24, 2015, 07:45:27 pm
Querying glyphs so that they are cached before being used is not "dirty". We could as well create a Font::preload(charset, size) function and it would look cleaner although exactly identical. What's dirty is assuming that all your glyphs fit in a single texture, which heavily depends on your GPU capabilities and on SFML internal code ;)
Title: Re: Generating the entire glyphs texture
Post by: zsbzsb on November 27, 2015, 03:37:00 pm
What's dirty is assuming that all your glyphs fit in a single texture

All glyphs of the same character size are guaranteed by SFML to fit in a single texture.
http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Font.php#a887368a4e6a3dfa32dea89d2af315951
Title: Re: Generating the entire glyphs texture
Post by: tanis on November 30, 2015, 09:22:57 am
All glyphs of the same character size are guaranteed by SFML to fit in a single texture.

I guess it depends on the size of the font. If it's too big, then it won't fit in a single texture. I don't know what happens internally in SFML at that point though.
Title: Re: Generating the entire glyphs texture
Post by: Laurent on November 30, 2015, 10:22:26 am
It's true that SFML doesn't handle this case, but it doesn't guarantee anything: if they don't fit, new glyphs are discarded and a warning is printed on sf::err().