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

Author Topic: SFML 1.6 - RenderWindow doesn't write text to screen  (Read 1085 times)

0 Members and 1 Guest are viewing this topic.

chilunliu

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
SFML 1.6 - RenderWindow doesn't write text to screen
« on: October 16, 2013, 11:02:28 am »
Hi all;

I'm trying to write some text in a pong game I'm trying to work through. Here is the code (does compile fine, using SFML 1.6 - please don't kill me, this is what i have to work with atm). For some unknown reason to me, I cannot see any text on the window when trying to feed the text to the renderwindow function. Can anyone advise on why this is the case and how I can remedy this problem?

Thank you
Chilun



// RESET BALL TO MIDDLE OF SCREEN AND RESET TIMER TO 0
GetSprite().SetPosition(Game::SCREEN_WIDTH/2, Game::SCREEN_HEIGHT/2);
_angle = (float)sf::Randomizer::Random(0,360);
_velocity = 220.0f;
_elapsedTimeSinceStart = 0.0f;

// ------------------------------------- DRAW TEXT TO SCREEN

// declare and load font file (.ttf)
sf::Font font;
font.LoadFromFile("PLANE.ttf", 100);

// create text object
sf::String text("YOU LOSE", font, 100);

// set colour
text.SetColor(sf::Color::Yellow);

text.SetSize(10.f);
text.SetPosition(0, 10);

// draw to screen
sf::RenderWindow window;
window.Draw(text);
                               
//update window
window.Display();

// ---------------------------------------------------------

 

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 1.6 - RenderWindow doesn't write text to screen
« Reply #1 on: October 16, 2013, 11:05:44 am »
Please provide a complete and minimal example. Your draw calls are supposed to be in a loop, and don't forget event handling. Please refer to the online tutorials to see the basic usage of SFML.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

chilunliu

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: SFML 1.6 - RenderWindow doesn't write text to screen
« Reply #2 on: October 16, 2013, 06:32:06 pm »
Hi;

I the tutorial for version 1.6 is very basic for writing text to the screen so I had to adapt my version with the 2.1 tutorial. I followed the example at the bottom of the following page: http://sfml-dev.org/tutorials/1.6/graphics-fonts.php. I've located many different examples, most of them don't have draw calls within loops, just set font, size, colour and feed this into a renderwindow variable, which should at least write something to the screen (based on code I've found online).

Chilun

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 1.6 - RenderWindow doesn't write text to screen
« Reply #3 on: October 16, 2013, 06:48:53 pm »
No, in order to draw something, you need a main loop as described here. Just use the naming conventions of SFML 1.6 in your case. I point you to the 2.1 version because it explicitly emphasizes that this is the only way you should do it.

There are of course example codes which don't use that loop, but they don't intend to be complete. Once you've seen the basic concept of input handling and rendering, it's pointless to repeat it in every single code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

chilunliu

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: SFML 1.6 - RenderWindow doesn't write text to screen
« Reply #4 on: October 18, 2013, 12:32:23 pm »
I see, Thanks for your help Nexus. I appreciate this. Chilun

 

anything