Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFML "failed to create the font face" issue

Tags:

c++

fonts

sfml

I'm using SFML in Visual Studio 2015 to make a game that requires me to print text. I try to load fonts and keep getting an error that says "failed to create the font face". I've tried loading several different fonts and none of them work, and they are in the correct directory, which is the folder where my project is located.

This is literally all it is, and it doesn't work:

 sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;

The ttf file for arial is in the same folder as the project itself, which is what seems to solve the problem for everyone else I find online who has the same issue. Any idea why the font still won't load?

like image 515
SBE Avatar asked Apr 18 '16 22:04

SBE


3 Answers

The simple answer is, the file is not in your current working directory when you run your executable.

Try to put in a fully qualified filename. It will work.

Using Visual Studio, most likely this is the directory where your .vcxproj file resides.

If this does not work, you can find out what your current working directory is by checking this post for a generic way how to find out your current directory.

As a quick hack, you could just create a file when your program starts. Start once and check where the file gets created. This is the current directory.

like image 191
nvoigt Avatar answered Oct 05 '22 14:10

nvoigt


I fixed with this:

sf::Font font;
if (!font.loadFromFile("../arial.ttf")){
   return EXIT_FAILURE;
}

I'm using CLion on Ubuntu using SMFL also.

like image 35
Jhon Paul Avatar answered Oct 05 '22 13:10

Jhon Paul


To add to this, I was experiencing this same error when I thought I'd had everything typed properly. What ultimately ended up being the issue was that I had written .tff for the font file rather than .ttf, which, once corrected, fixed the problem.

like image 24
the-wastelander Avatar answered Oct 05 '22 13:10

the-wastelander