SFML community forums

Help => General => Topic started by: Moosyu on April 25, 2022, 02:20:39 am

Title: Text isn't working
Post by: Moosyu on April 25, 2022, 02:20:39 am
I'm following the text and font tutorial almost word for word, made sure to download arial font and put it into the same dictionary as main.cpp and yet I'm getting this error:
Failed to load font "arial.ttf" (failed to create the font face)

This is my code:
#include <iostream>
#include "SFML/Graphics.hpp"
#include "SFML/Window.hpp"
#include "SFML/System.hpp"

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 800), "SFML works!");
   
sf::CircleShape shape(100.f);
   
shape.setFillColor(sf::Color::Green);
   
sf::Clock clock;

sf::Font font;

font.loadFromFile("arial.ttf");

sf::Text text;

text.setFont(font);

text.setString("Hello world");

text.setCharacterSize(24);

text.setFillColor(sf::Color::Red);

text.setStyle(sf::Text::Bold);


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            std::cout << clock.getElapsedTime().asSeconds() << std::endl;

            if (event.type == sf::Event::Closed)
                window.close();
       
        window.clear();

        window.draw(shape);

        window.draw(text);

        window.display();

        }
    }
    return 0;
}
 
Title: Re: Text isn't working
Post by: eXpl0it3r on April 25, 2022, 10:01:05 am
Files are loaded from the working directory, which can be different from the executable directory when you run the application from the IDE.