I'm just starting to learn SFML so I don't understand why this code isn't working. As I understand it, the font simply cannot be loaded, which is why the error occurs. I tried everything I could, absolute path, different fonts, different paths, ran as administrator.
Error:
Failed to load font "AtЇE"
arial.ttf HїO╓▓█ПьУ·┤╟Ў∙FфT}ь< ─Ў∙" (failed to create the font face).
Here is the code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Text");
sf::Font font;
if (!font.loadFromFile("arial.ttf")) {
return EXIT_FAILURE;
}
sf::Text text("Hello, SFML!", font, 30);
text.setFillColor(sf::Color::White);
text.setPosition(200, 300);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
return EXIT_SUCCESS;
}
Some additional information: I'm working in Visual Studio 2022 and my operating system is Windows 11