SFML community forums

Help => General => Topic started by: foulehistory on September 11, 2022, 12:45:18 am

Title: Load Font
Post by: foulehistory on September 11, 2022, 12:45:18 am
Hello, I use jetbrains rider.
I can't load any font in my project
Quote
    sf::Font font;
    if (font.loadFromFile("C:\\Windows\\Fonts\\Arial.ttf"))
    {
        isValid = true;
        currentText = sf::Text("Hello World", font, 24);
        Debug::Log("Load font aerial.ttf");
    }
    else
    {
        isValid = false;
        currentText = sf::Text("Hello World", font, 24);
        Debug::Log("Can't Load font aerial.ttf");
    }

and I really don't know why they don't want to, I have no error message, just the function returns false
Title: Re: Load Font
Post by: eXpl0it3r on September 20, 2022, 08:11:36 pm
If font loading fails, SFML will always be printing the reason as to why.
Make sure to check the output/console window. If you build on Windows, make sure you're using the subsystem console, otherwise you don't get a console and thus no logging.
Alternatively you can redirect the sf::err() buffer to your own logging stream.

How do you use Rider for C++ projects? Do you mean CLion?
Title: Re: Load Font
Post by: king.randow on March 27, 2024, 10:33:26 pm
Came for the exact same reason. Everything works of SFML 2.6.1 64 bit version, aside from the font.

Running
sf::Font font;
if (!font.loadFromFile("times.ttf"))
    std::cout << "Could not load font." << std::endl;
return EXIT_SUCCESS;

Returns this message when running
Failed to load font "░╣
8times.ttf      ╤ó╨÷╨rµ╣e └o╟ -ÉG√" (failed to create the font face)
Could not load font.

C:\...\Primer\x64\Debug\Primer.exe (process 30992) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.

The times.ttf is the one copied from the C:\Windows\Fonts folder into the Debug folder where the exe file is. I also tried coping in every other folder of the Primer Project as well as running C:\\Windows\\Fonts\\times.ttf. All without luck.

This is my whole code:
#include <SFML/Graphics.hpp>
#include <iostream>


using namespace std;

int main()
{
    sf::Font font;
    if (!font.loadFromFile("times.ttf"))
        std::cout << "Could not load font." << std::endl;
    return EXIT_SUCCESS;


    return 0;
}
Title: Re: Load Font
Post by: eXpl0it3r on March 28, 2024, 07:15:10 am
Make sure, you're actually linking debug libraries in debug mode (the ones with the -d) suffix.
Title: Re: Load Font
Post by: king.randow on March 28, 2024, 12:33:58 pm
aaahhhh thank you for this. This is working now!

For others that might come across this. Here is what I needed to change:

Go to your project properties -> Linker -> Input -> Additional Dependencies:

For debug configuration:
sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-audio-d.lib
sfml-main-d.lib

For release configuration:
sfml-graphics.lib
sfml-window.lib
sfml-system.lib
sfml-audio.lib
sfml-main.lib