SFML C++ Failed to load font

Viewed 226

As I was creating a program that would print text, that I input, out onto the window I have stumbled on a problem. My font always fails to load. I tried putting it in multiple directories, even putting in the whole path to the file yet it does not work. The text printing will not work without the font, therefore I can't progress

Thx for your answers

Here is the code

#include <SFML/Graphics.hpp>
#include <iostream>

int main() {

    sf::String playerInput;
    sf::Font font;
    sf::Text playerText;

    if (!font.loadFromFile("arial.ttf")) {
        printf("Failed to load font.\n");
    }

    playerText.setFont(font);
    playerText.setFillColor(sf::Color::Red);

    sf::RenderWindow window(sf::VideoMode(600, 600), "Window", sf::Style::Close | sf::Style::Resize);
    while (window.isOpen()) {

        sf::Event evt;
        while (window.pollEvent(evt)) {
            switch (evt.type) {
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::TextEntered:
                        playerInput += evt.text.unicode;
                        playerText.setString(playerInput);
                    break;
                
                default:
                    break;
            }
        }

        window.clear();
        window.draw(playerText);
        window.display();
    }

    return 0;
}
1 Answers

Edit: I forgot to mention that I am using SFML 2.5.1 for Visual Studio 2017 64bit, while using Visual Studio 2019

Related