简体   繁体   中英

C++ SFML Font Problems

sf::RenderWindow window(sf::VideoMode(800, 600), "CALENDAR");

sf::Font font;
if (!font.loadFromFile("arial.ttf"))
    std::cout << "no\n";

sf::Text text1;
text1.setFont(font);
text1.setCharacterSize(30);
text1.setColor(sf::Color::Black);
text1.setStyle(sf::Text::Regular);
text1.setString("ttestst");

while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        switch (event.type){
        case sf::Event::Closed:
            window.close();
        }
    }

    window.clear(sf::Color::White);
    window.draw(text1);
    window.display();
}

This code isn't displaying text to the screen, and the font isn't loading, i've no idea what to do, any help is appreciated.

It seems like the path to the font is wrong. If you're using "arial.ttf" , make sure that font file is in the same directory where your program starts executing.

As @twsaef said you can also use absolute path, but not in this way:

"C:\Coding\Fonts\Arial.ttf"

This is wrong. Instead of single backslash \\ you have to use double backslash \\\\ :

"C:\\Coding\\Fonts\\Arial.ttf"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM