Hello. I'm a student using SFML for one of my projects (C++) and this error has been driving me nuts.
I'm trying to load a truetype font using SFML. All other SFML features that I've used so far have been working fine (although none of them involve reading files), but this specific one seems to be failing every time.
I've tried to load the font using loadFromFile() and loadFromStream(). The first returns no error (but the method returns "false") and the latter prints "Failed to load font from stream (failed to create the font face)".
This led me to think that SFML is having trouble reading files from my disk. However, the ttf file is definitely in the working directory - I've checked this by having the program create a file and checking the directory it appears in. The ttf file is also definitely valid (I can open it using other software) and appropriately named.
As part of this project, I've already used another library (pugixml) to read xml files, and have had no trouble reading from the same directory that I am trying to access here, so this doesn't seem to be a permission problem.
Here is the relevant code:
sf::Font font;
sf::FileInputStream stream;
if (!stream.open("arial.ttf")) {
std::cout << "error\n";
}
if (!font.loadFromStream(stream)) {
std::cout << "error1\n";
}
std::ofstream outfile("testfile.txt");
if (!font.loadFromFile("arial.ttf")) {
std::cout << "error3\n";
}
All three of these errors are triggered. I've #include'd <SFML\Graphics.hpp> at the top of the file.
Any help would be really appreciated! Thank you in advance!