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

Author Topic: Text doesn't show up, but everything seems perfectly fine  (Read 2907 times)

0 Members and 1 Guest are viewing this topic.

NunoLava1998

  • Newbie
  • *
  • Posts: 2
    • View Profile
Text doesn't show up, but everything seems perfectly fine
« on: May 01, 2018, 03:50:45 pm »
Hello! This is my first post on the SFML forum, so I hope it doesn't break any rules.

I'm making a test application in C++ with Visual Studio and SFML, and for some reason, the text fails to show up and I have no idea why.

It compiles perfectly and the font (munro.ttf) is in the same folder as main.cpp.

Here's my main function (Yes, it is just one file with one function, and it includes SFML/Graphics.hpp and windows.h):

        sf::RenderWindow window(sf::VideoMode(1280, 720), "Example App");
        window.display();

        sf::Font font;
        sf::Text text;

        if (!font.loadFromFile("munro.ttf")) {
                return 1;
        }

        font.loadFromFile("munro.ttf");
        text.setCharacterSize(24);
        text.setStyle(0x02); // (Bold. Not important since it doesn't show up with it set to bold or not.)
        text.setFont(font);
        text.setString("Testing text");
        window.draw(text);
        Sleep(4000); // This is why windows.h is needed.
 

I'm on Windows 10 and use a GTX 950 GPU with the proper drivers. However, before SFML could display text perfectly with the exact same settings, so I don't understand what's going on.

I'm using the static version of SFML, and as expected, it only produces a .exe and .pdb file (debug information, like symbols in gdb) that works perfectly. I am using the static version of SFML for both debug and release versions, and do use the correct .lib's (like sfml-audio-s-d.lib for Debug and sfml-audio-s.lib for Release).

There is no part in the log that even mentions anything about an error in SFML, so I won't include it. The only errors is the amount of "no .pdb file available" which is expected because it's Visual Studio.

Thank you for any help!


EDIT: window.display(); needed to be after window.draw(text);. Thanks for helping me!
« Last Edit: May 01, 2018, 04:06:30 pm by NunoLava1998 »

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text doesn't show up, but everything seems perfectly fine
« Reply #1 on: May 01, 2018, 03:59:57 pm »
You're missing a game loop.
Also, don't sleep for 4 seconds. (Don't sleep for more than 1 ms I'd say.
Your loop needs to be running very often.
Also, window.display() needs to be at the end.

while (window.isOpen()){
   window.clear(); //you can put a color in the parameters to set your window background to ex: Color::Red
   sf::Font font;
   sf::Text text;

   if (!font.loadFromFile("munro.ttf")) { return 1; }

   font.loadFromFile("munro.ttf");
   text.setCharacterSize(24);
   text.setStyle(0x02); // (Bold. Not important since it doesn't show up with it set to bold or not.)
   text.setFont(font);
   text.setString("Testing text");
   window.draw(text);
   window.display();
}

Edit: See here for tut about game loops:
« Last Edit: May 01, 2018, 04:01:51 pm by CowNation »

NunoLava1998

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Text doesn't show up, but everything seems perfectly fine
« Reply #2 on: May 01, 2018, 04:03:49 pm »
It's not supposed to be a game loop, it's just designed to say some text, wait for a bit and then exit.

I'll see if that works, though.

EDIT: Oh, window.display(); needed to be at the end. Thanks!
« Last Edit: May 01, 2018, 04:05:31 pm by NunoLava1998 »

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Text doesn't show up, but everything seems perfectly fine
« Reply #3 on: May 01, 2018, 04:06:50 pm »
No problem! GLHF with SFML!

 

anything