SFML community forums

Help => Graphics => Topic started by: mickes27 on June 19, 2017, 06:48:33 pm

Title: Problem with text
Post by: mickes27 on June 19, 2017, 06:48:33 pm
Hey. I have a code:

Quote
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
#include <iostream>

using namespace sf;
int main()
{
   
   sf::RenderWindow window(sf::VideoMode(320, 240), "Font Test");
   Font font;
   font.loadFromFile("ditr.ttf");
   Text text;
   text.setFont(font);
   text.setString("Hello World");
   text.setFillColor(Color::Red); //Maybe a color
   text.setCharacterSize(24);

   while (window.isOpen())
   {
      Event event;
      while (window.pollEvent(event))
      {
         if (event.type == Event::Closed)
            window.close();

      }
      text.setPosition(250, 250);
      window.clear(Color::White);
      window.draw(text);
      window.display();
   } //while
   return 0;
}

But when I compile, I have a white screen, without text. Can you tell me why?
Title: Re: Problem with text
Post by: Arcade on June 19, 2017, 07:39:05 pm
sf::RenderWindow window(sf::VideoMode(320, 240), "Font Test");
...
text.setPosition(250, 250);

It looks like you are trying to draw your text outside of the window. Your window height is set to 240 pixels, but you are drawing text with a Y position of 250.

Also, make sure you check the return value of font.loadFromFile("ditr.ttf") to make sure it doesn't fail.
Title: Re: Problem with text
Post by: mickes27 on June 19, 2017, 08:33:06 pm
Thank you so much. Didn't realise I am out of window