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

Author Topic: Text displays solid [FIXED]  (Read 1640 times)

0 Members and 1 Guest are viewing this topic.

PooBear

  • Newbie
  • *
  • Posts: 3
    • View Profile
Text displays solid [FIXED]
« on: March 06, 2013, 01:08:20 pm »
I'm a newbie so forgive what must be a stupid mistake. When I display text it renders as a solid rectangle of colour for each glyph. The size looks about right for each character. I based my first project on the pong example, so I've tried the same ttf font and arial.

Anybody see anything wrong with this code->
I've removed a bit of it for brevity.

sf::Font *pFont(nullptr);

int main()
{
   const int gameWidth = 800;
   const int gameHeight = 600;

   // Create the window of the application
   pWindow = new sf::RenderWindow(sf::VideoMode(gameWidth, gameHeight, 32), "Mouse and cheese");
   pWindow->setVerticalSyncEnabled(true);

   // Load the text font
   pFont=new sf::Font;
   if (!pFont->loadFromFile("resources/arial.ttf"))
      return EXIT_FAILURE;

   // Initialize the pause message
   sf::Text titleMessage;
   titleMessage.setFont(*pFont);
   titleMessage.setCharacterSize(40);
   titleMessage.setPosition(170.f, 150.f);
   titleMessage.setColor(sf::Color::White);
   titleMessage.setString("Mouse and Apples");

   while (pWindow->isOpen())
   {
      // Handle events
      sf::Event event;
      while (pWindow->pollEvent(event))
      {
         // Window closed or escape key pressed: exit
         if (event.type == sf::Event::Closed)
         {
            pWindow->close();
            break;
         }

      }


      // Clear the window
      pWindow->clear(sf::Color(50, 200, 50));

      pWindow->draw(titleMessage);

      // Display things on screen
      pWindow->display();
   }
   delete pFont;
   delete pWindow;
   return EXIT_SUCCESS;

}

« Last Edit: March 06, 2013, 05:24:32 pm by PooBear »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Text displays solid
« Reply #1 on: March 06, 2013, 01:16:00 pm »
You should use the code=cpp tag to post code and provide information about your OS, compiler, toolchain, SFML version, graphics card and driver version, etc. etc. (see here). ;)

As for the problem you might want to search the forum a bit, there have been quite a few similar threads.
Maybe an update to the latest SFML commit will already fix it.

Looking at your code I'm asking myself whether you've been working a lot with C or Java, because you don't need to make very thing a pointer, especially not raw pointers. Thus you should never use pointers if it's not nessecary, make sure if you couldn't use a reference instead and probably in all cases use smart pointers instead of raw pointers (see here for more details).
Besides that you shouldn't use global variables and especially not global SFML resources (i.e. sf::Font).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PooBear

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Text displays solid
« Reply #2 on: March 06, 2013, 05:23:56 pm »
Why is there always someone who jumps in with "try searching the forums"  ::)
<sigh>
I already have, obviously, or I wouldn't be posting  :)

Anyway...

Turns out it's something to do with SFML 2.0, if you just get the pong example and try printing text while the bats and ball are visible you get exactly the same problem. Maybe it's already fixed, my version says "LaurentGomila-SFML-527bb28".

Downloaded SFML 1.6 and it works fine.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Re: Text displays solid
« Reply #3 on: March 06, 2013, 06:04:11 pm »
Why is there always someone who jumps in with "try searching the forums"  ::)
<sigh>
I already have, obviously, or I wouldn't be posting  :)
Because those 'someones' have read about every post on this forum and thus knows exactly what has been asked before.
For your problem there are at least 2 other threads, but I don't feel like looking for them, thus I suggest to search the forum. ;)
I think it says something like: Drawing a rectangle breaks sf::Text

Downloaded SFML 1.6 and it works fine.
SFML 1.6 is outdated and quite a bit different than SFML 2 (see the FAQ on the wiki).

We still don't know your OS, GPU and whether your GPU drovers are uptodate. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

PooBear

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Text displays solid [FIXED]
« Reply #4 on: March 06, 2013, 07:11:40 pm »
You do realise how common it is to be told "search the forums" though right? Very frustrating  :) I'd looked through about 20 threads on text and font problems that are not related to my issue.

"Drawing a rectangle breaks sf::Text"

Aha, that's the key piece of missing information, googling that  took me straight to the right thread.

My laptop has ATI hardware like many of those posting with the same problem, I can't update the drivers as it's locked to the manufacturer who seems to hardly ever bother updating. However, switching to a desktop machine that also has an ATI gpu (but has updated drivers) and the problem is gone. So it does seem driver related.

Thanks for your help  :)


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Text displays solid [FIXED]
« Reply #5 on: March 06, 2013, 09:43:02 pm »
You do realise how common it is to be told "search the forums" though right? Very frustrating  :)
And you do realize how often we get questions where a simple search can answer the problem, people often just don't do it. Very frustrating as well. ;)
Maybe I could've given more information in the first thread though.

To prevent the 'search the forums' it's always good to state, that you did search, but maybe lack the correct keywords. With such an approach the only answer one can give (without being an jackass) are some keywords to search for or directly results. ;)

I'm sorry if I've been a bit too harsh. :)

My laptop has ATI hardware like many of those posting with the same problem, I can't update the drivers as it's locked to the manufacturer who seems to hardly ever bother updating.
Yeah I had that with my EliteBook 8460p as well, but now I got a newer version, which lets me get the driver directly from AMD.

Wasn't there a fix, like calling glFlush()? I don't remember the specifics of the discussion in the other threads.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/