draw text in sfml code example

Example 1: sfml draw tex

sf::Text text;

// select the font
text.setFont(font); // font is a sf::Font

// set the string to display
text.setString("Hello world");

// set the character size
text.setCharacterSize(24); // in pixels, not points!

// set the color
text.setFillColor(sf::Color::Red);

// set the text style
text.setStyle(sf::Text::Bold | sf::Text::Underlined);

...

// inside the main loop, between window.clear() and window.display()
window.draw(text);

Example 2: sfml draw tex

sf::Font font;
if (!font.loadFromFile("arial.ttf"))
{
    // error...
}

Tags:

Cpp Example