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

Author Topic: SFML text display problem under Linux  (Read 565 times)

0 Members and 1 Guest are viewing this topic.

JLesage

  • Newbie
  • *
  • Posts: 7
    • View Profile
SFML text display problem under Linux
« on: May 09, 2023, 01:07:26 pm »
Hello. I am learning C++ and SFML under Linux(Pop!_OS 22.04 LTS). I run some code ()to display some text on my window, I have no error when running, but the text does not display. Please help me.

Note: I did the library inclusions and the constants declaration in another file(.hpp).

#include "main.hpp"
 
#include <iostream>
 
sf::Font font;
 
int main(){
 
 
    void gestionEntrees(sf::Event, sf::RenderWindow &window);
 
    void chargerPolice();
 
   
    sf::Text txt;
    txt.setFont(font);
    txt.setString("Hello, World.");
    txt.setCharacterSize(26);
    txt.setFillColor(sf::Color::Blue);
    txt.setStyle(sf::Text::Bold | sf::Text::Underlined);
 
   
 
    sf::RenderWindow window(sf::VideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE, 32), "Mon premier jeu", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);
 
    window.setVerticalSyncEnabled(true);
 
    while(window.isOpen()){
 
        sf::Event event;
        while(window.pollEvent(event)){
            // fermeture de la fenêtre lorsque l&#39;utilisateur le souhaite
            gestionEntrees(event, window);
             
        }
 
       
        window.clear(sf::Color::White);
 
         
       
        window.draw(txt);
 
         
        window.display();
 
    }
 
    return 0;
 
}
 
 
void gestionEntrees(sf::Event event, sf::RenderWindow &window){
    if (event.type == sf::Event::Closed)
        window.close();
}
 
//Load font
void chargerPolice(){
    if (!font.loadFromFile("/usr/share/fonts/opentype/noto/NotoSansCJK-Black.ttc"))
        throw("Erreur de chargement de police");
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
Re: SFML text display problem under Linux
« Reply #1 on: May 09, 2023, 01:22:59 pm »
You shouldn't use a global font, as this can lead to crashes, due to undefined initialization and destruction orders.
Better to just wrap your application in a dedicated class.

I'm not sure if Freetype/SFML supports TTC, as such check that the font can be loaded. If not, you might need to provide a different format, like TTF.

Also, please don't use the SFML Development sub-forum, as the description says, that's for development discussions-only. When asking for help, use the Help sub-forums ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

JLesage

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: SFML text display problem under Linux
« Reply #2 on: May 10, 2023, 02:22:15 pm »
Thanks for the reply, @eXpl0it3r.