Search code examples
c++sfml

Why does sf::Text display dots instead of numbers?


I've got a problem. I'm trying to display numbers on the screen with this code:

sf::Text text;
text.setCharacterSize(24);
text.setFont(font);
text.setFillColor(sf::Color::Red);
std::string str = "";
    for (int i = 1; i <= 6; i++)
    {
        str += std::to_string(i);
        str += "\n";
    }
text.setString(str);

And the problem is when I draw text with window.draw(text) on the screen I'm getting something like this:

.
.
.
.
.
.

Any idea why?


Solution

  • It's likely that your font has failed to load. Be sure to check the return value when you're loading your font, e.g.

    if (!font.loadFromFile("arial.ttf"))
    {
        // error
    }