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

Author Topic: SFML Project not rendering shapes  (Read 1474 times)

0 Members and 1 Guest are viewing this topic.

mindoo

  • Newbie
  • *
  • Posts: 1
    • View Profile
SFML Project not rendering shapes
« on: November 01, 2016, 07:15:24 pm »
I'm currently trying to learn how to use the sfml api, but my whole draw function doesn't work and doesn't display anything. I did put breakpoints and verified that the program does go through that function, and it does, but it still doesn't work.

This is my function that doesn't work :
void GameStateStart::draw() {

    this->game->window.clear();

    /*Modify the colour of the background*/
    background.getRectangle().setFillColor(sf::Color::Green);
    background.drawObject(&game->window);

    /*Create the font for the text*/
    sf::Font font;
    font.loadFromFile("Pacifco.ttf");

    /*Test*/
    sf::Text title2;
    title2.setFillColor(sf::Color::Blue);
    title2.setFont(font);
    title2.setPosition(sf::Vector2f(300, 100));
    title2.setString("Tic Tac SFML");
    title2.setCharacterSize(25);
    this->game->window.draw(title2);

    /*Edit title text objects*/
    title.getText()->setFillColor(sf::Color::Blue);
    title.getText()->setFont(font);
    title.getText()->setPosition(sf::Vector2f(300, 100));
    title.getText()->setString("Tic Tac SFML");

    /*Edit instructions text object*/

    instructions.getText()->setFillColor(sf::Color::Blue);
    instructions.getText()->setFont(font);
    instructions.getText()->setPosition(sf::Vector2f(300, 450));
    instructions.getText()->setString("Press the spacebar to continue");

    /*draw the 2 text objects*/
    title.drawObject(&this->game->window);
    instructions.drawObject(&this->game->window);

    this->game->window.display();

    return;
}

BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: SFML Project not rendering shapes
« Reply #1 on: November 02, 2016, 06:58:45 am »
I don't see why it doesn't render anything, but I still wanted to tell you that loading the font every time you want to draw something is not a good idea and wasting a lot of cpu time.

How did you create your window and assign it to "this->game->window"? Could you show this part of the code please?
« Last Edit: November 02, 2016, 07:00:20 am by BlueCobold »