Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Text isn't working  (Read 1018 times)

0 Members and 1 Guest are viewing this topic.

Moosyu

  • Newbie
  • *
  • Posts: 1
    • View Profile
Text isn't working
« 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;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Text isn't working
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/