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

Author Topic: create a window, then close it and re-open it?  (Read 8131 times)

0 Members and 1 Guest are viewing this topic.

smurf

  • Newbie
  • *
  • Posts: 36
    • View Profile
create a window, then close it and re-open it?
« on: July 07, 2021, 09:44:22 pm »
I'm familiar with creating a single window, and when they click the X, I close the window and exit the program.

But now I'm working on a different program which will have many windows. The windows can be closed, and you can always go back to the "main" window and click a button to open other additional windows.

I see from the documentation that RenderWindow/Window has a close() function that:

"Close the window and destroy all the attached resources.

After calling this function, the sf::Window instance remains valid and you can call create() to recreate the window. All other functions such as pollEvent() or display() will still work (i.e. you don't have to test isOpen() every time), and will have no effect on closed windows.
"


What does it mean that the attached resources are destroyed but the window is still valid?
Is this close(), create() pair the right thing for me to be doing in my scenario?

What if I really wanted the window to be completely destroyed and I'm OK with create() creating a truly brand new window, instead of resurrecting some half-dead one?

Finally, I'm using the C# bindings, and I don't actually see a create() method. Is the equivalent simply the C# RenderWindow() constructor? If so how different is the C# version from the C++ documentation that I'm reading?

Main question, how should I go about allowing new windows to be created and destroyed on the fly?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: create a window, then close it and re-open it?
« Reply #1 on: July 09, 2021, 08:08:07 am »
The doc means that the C++ instance is still valid, but the OS window is really destroyed.
In C#, you should rather destroy the instance and create a new one.

Quote
I don't actually see a create() method. Is the equivalent simply the C# RenderWindow() constructor?
Yes.

Quote
If so how different is the C# version from the C++ documentation that I'm reading?
Just that (constructors instead of create/load functions).
Laurent Gomila - SFML developer