SFML community forums

Help => Window => Topic started by: Grimnack on April 05, 2021, 09:27:33 pm

Title: on start,window freezes
Post by: Grimnack on April 05, 2021, 09:27:33 pm
So the window on starting,simply freezes.All i see is the border of the window and the desktop background.Even with the simplest example on this website,i get that rezult.

#include <SFML/Window.hpp>
int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");
    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }
    return 0;
}
Now this doesn't happen with renderWindow,but renderWindow starts and quits immediatly.
At least he starts....i get a glimpse of the window.
I use Ubuntu  Mate 20.04.2 LTS 64bit
latest sfml
gcc 9.3.0
Thoughts?
Title: Re: on start,window freezes
Post by: Stauricus on April 05, 2021, 10:50:22 pm
you forgot to clear and display the window

window.clear()
window.display()

inside the 'while(window.isOpen){' loop


EDIT: one more thing, you should use sf::RenderWindow, not sf::Window.
Title: Re: on start,window freezes
Post by: Grimnack on April 05, 2021, 11:28:53 pm
error: ‘class sf::Window’ has no member named ‘clear’.
I think those are for renderWindow class.
Title: Re: on start,window freezes
Post by: Stauricus on April 06, 2021, 01:29:58 am
it is, i edited my post above. do you have any particular reason to use sf::Window? if you just want to have a minimalist SFML window, use RenderWindow.
Title: Re: on start,window freezes
Post by: Grimnack on April 06, 2021, 10:05:13 pm
i dont have any particular reason to use sf::Window.Just following examples on the website.So i have no practical need to sf::Window?
sf::renderWindow would suffice for all my needs?
Title: Re: on start,window freezes
Post by: Stauricus on April 07, 2021, 01:37:54 am
yes, sf::RenderWindow is the 'default' window for SFML programs. it inherits from sf::Window, which would be more targeted to using some OpenGL calls directly.