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

Author Topic: SFML Window not responding & can't close it.  (Read 2020 times)

0 Members and 1 Guest are viewing this topic.

Justbod

  • Newbie
  • *
  • Posts: 9
    • View Profile
SFML Window not responding & can't close it.
« on: January 27, 2019, 05:38:46 pm »
Hi guys, I'm just started working on a new project of mine. I just finished the game loop and everything seemed fine but the window rendered by SFML is not responding and when I hover my mouse over it the cursor will change to a loading symbol. I added some console messages and the loop is still running.

void update_game(sf::RenderWindow& window)
{
        std::cout << "update";
        window.clear();
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
        window.draw(shape);
}

void display_game(sf::RenderWindow& window, float interpolation)
{
        std::cout << "display";
        window.display();
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

        const int TICKS_PER_SECOND = 25;
    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    const int MAX_FRAMESKIP = 5;

    DWORD next_game_tick = GetTickCount();
    int loops;
    float interpolation;

    //bool game_is_running = true;
    while(window.isOpen())
        {
        loops = 0;
        while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)
                {
                        std::cout << "tickloop";
                        update_game(window);
            next_game_tick += SKIP_TICKS;
            loops++;
        }

        interpolation = float( GetTickCount() + SKIP_TICKS - next_game_tick )
                        / float( SKIP_TICKS );
        display_game(window, interpolation);
    }

        return 0;

}
« Last Edit: January 27, 2019, 06:02:46 pm by Laurent »
🧃🦔

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML Window not responding & can't close it.
« Reply #1 on: January 27, 2019, 06:03:20 pm »
You must add an event loop in your code. Please read the tutorials carefully.
Laurent Gomila - SFML developer

 

anything