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

Author Topic: Problem with text  (Read 1965 times)

0 Members and 1 Guest are viewing this topic.

mickes27

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Problem with text
« 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?

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Problem with text
« Reply #1 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.

mickes27

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: Problem with text
« Reply #2 on: June 19, 2017, 08:33:06 pm »
Thank you so much. Didn't realise I am out of window

 

anything