Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to render text without setting a font.

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
string culoare;
int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        sf::Text text;
            //atext.setFont();
            text.setString("HelloWorld");
            text.setCharacterSize(20);
            text.setStyle(sf::Text::Bold);
            text.setColor(sf::Color::White);
            text.setPosition(0,0);
            window.draw(text);
            window.clear(sf::Color::Green);
            window.display();
    }

    return 0;
}

This just make a green window, but doesn't display text.

share|improve this question

1 Answer 1

What's happening is you're clearing the screen after drawing the text. So this

        window.draw(text);
        window.clear(sf::Color::Green);

should be this

        window.clear(sf::Color::Green);
        window.draw(text);

If it still doesn't display anything, you definitely need to set a font!

share|improve this answer
    
Thanks a lot! Works! –  Stucky Feb 15 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.