Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Generating the entire glyphs texture  (Read 2561 times)

0 Members and 1 Guest are viewing this topic.

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
Generating the entire glyphs texture
« 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Generating the entire glyphs texture
« Reply #1 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.
Laurent Gomila - SFML developer

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Generating the entire glyphs texture
« Reply #2 on: November 24, 2015, 04:39:12 pm »
As dirty as it is but it definitely works well. Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Generating the entire glyphs texture
« Reply #3 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 ;)
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Generating the entire glyphs texture
« Reply #4 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
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Generating the entire glyphs texture
« Reply #5 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Generating the entire glyphs texture
« Reply #6 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().
Laurent Gomila - SFML developer

 

anything