Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Load Font  (Read 830 times)

0 Members and 1 Guest are viewing this topic.

foulehistory

  • Newbie
  • *
  • Posts: 1
    • View Profile
Load Font
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Load Font
« Reply #1 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?
« Last Edit: March 28, 2024, 07:14:24 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

king.randow

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Load Font
« Reply #2 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;
}
« Last Edit: March 28, 2024, 07:15:44 am by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Load Font
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

king.randow

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Load Font
« Reply #4 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

 

anything