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

Author Topic: [SOLVED] sf::Text not appearing on the screen  (Read 5789 times)

0 Members and 1 Guest are viewing this topic.

Munchor

  • Newbie
  • *
  • Posts: 16
    • View Profile
[SOLVED] sf::Text not appearing on the screen
« 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.
« Last Edit: December 30, 2012, 01:53:36 pm by Munchor »

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: sf::Text not appearing on the screen
« Reply #1 on: December 30, 2012, 04:51:55 am »
I don't see where you associate your text with a font.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: sf::Text not appearing on the screen
« Reply #2 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Munchor

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: [SOLVED] sf::Text not appearing on the screen
« Reply #3 on: December 30, 2012, 01:53:44 pm »
That was it, thank you!

the_composer

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: [SOLVED] sf::Text not appearing on the screen
« Reply #4 on: April 25, 2013, 06:23:41 am »
Could someone fix this on the documentation page? 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: [SOLVED] sf::Text not appearing on the screen
« Reply #5 on: April 25, 2013, 07:46:47 am »
Could someone fix this on the documentation page?
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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/