SFML community forums

Help => Graphics => Topic started by: Munchor on December 30, 2012, 04:37:49 am

Title: [SOLVED] sf::Text not appearing on the screen
Post by: Munchor on December 30, 2012, 04:37:49 am
First of all, here's my code:

#include "PlayState.hpp"

using namespace std;

PlayState::PlayState(Game *_game) {
  game = _game;

  /* Set up FPS string */
  fps.setCharacterSize(12);
  fps.setPosition(400, 320);
  fps.setColor(sf::Color::Red);
 
  player = new Player();

  currentMap = new Tilemap("res/map1.txt", &(game->window));
}

void PlayState::setup() { }

void PlayState::update() {
  sf::Event event;
  while (game->window.pollEvent(event)) {
    if (event.type == sf::Event::Closed) {
      game->window.close();
    } else if (event.type == sf::Event::KeyPressed) {
      if (event.key.code == sf::Keyboard::Escape) {
        game->window.close();
      }
    }
  }

  player->update();
}

void PlayState::draw() {
  game->window.clear();

  /* Draw the player */
  //game->window.draw(*player);

  /* Draw the map */
  //currentMap->draw(400, 320);

  /* Draw FPS */
  fps.setString("Hi");
  game->window.draw(fps);

  game->window.display();
}
 

The only thing I'm drawing to the screen is a sf::Text, but it's not appearing on the screen. I'm using built-from-git SFML. I tried an older build, and it worked, I could see the sf::Text. When I changed its color, though, I got a floating point exception.

Any ideas on what I'm doing wrong?

EDIT
I also tried to dynamically allocate the sf::Text fps; and then do "fps = new sf::Text();" and what not, but it also didn't work.
Title: Re: sf::Text not appearing on the screen
Post by: cire on December 30, 2012, 04:51:55 am
I don't see where you associate your text with a font.
Title: AW: sf::Text not appearing on the screen
Post by: eXpl0it3r on December 30, 2012, 06:57:20 am
The default font was removed in the Git version, so you'll have to load a font on your own and pass it to your sf::Text.
Title: Re: [SOLVED] sf::Text not appearing on the screen
Post by: Munchor on December 30, 2012, 01:53:44 pm
That was it, thank you!
Title: Re: [SOLVED] sf::Text not appearing on the screen
Post by: the_composer on April 25, 2013, 06:23:41 am
Could someone fix this on the documentation page (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Text.php)? It explicitly says you don't need to load a font, which left me wondering why the Text wasn't rendering for far too long.
Title: AW: Re: [SOLVED] sf::Text not appearing on the screen
Post by: eXpl0it3r on April 25, 2013, 07:46:47 am
Could someone fix this on the documentation page (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Text.php)?
The online documentation matches the online releases, in this case SFML 2.0RC. If you compile from source you'll also have to build the doc (it's just one flag in CMake).
Besides in a (few) weeks SFML 2, will be released with a new website and a proper doc for SFML 2.0. ;)