1
General / 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:
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;
}
#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;
}