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

Author Topic: Is there any way to have sf::Text not cache the new font texture into memory whe  (Read 143 times)

0 Members and 1 Guest are viewing this topic.

dsfsf

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
I am making a program using SFML on an old laptop, and its task is to print all Unicode characters, just like in this video:

However, after running for a while, the program will show the error:
"Failed to add a new character to the font: the maximum texture size has been reached."
I noticed that Text::setString() caches the textures of the characters rendered in the text into memory to speed up the next use of those textures, but my program clearly does not need this feature.

My current solution is:

Text::setString(character);
if (character % 500 == 0) {
    mainFont.loadFromFile(currentFont);
}

This is clumsy and wastes performance and memory.

Is there a solution?
One idea I had was to use FreeType to render the characters directly, but I feel like this would waste SFML's potential.


kimci86

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Instead of completely reloading the font from file, you could make a copy of the sf::Font instance before rendering characters, and use it to reset your working sf::Font instance from time to time by assigning to it. This will reuse the same underlying FreeType objects under the hood but start with new empty textures.
« Last Edit: Today at 08:34:26 am by kimci86 »