1 2 3 4 5 6 7
|
if(wnd.GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
sf::RenderWindow wn(sf::VideoMode(300, 400), "WND");
wn.Clear();
wn.Display();
}
|
'wn' here is your window. You made it local to this if block, so as soon as this if block exits, your 'wn' object goes out of scope and is destroyed, which kills the window.
You'll have to give 'wn' a broader scope if you want it to live longer.
Also, multiple windows gets tricky, since you'll need to poll events for each window. Right now your code is polling events for your main window 'wnd' (ie:
wnd.GetEvent
). You'll have to do the same with any other windows you want (like 'wn').
HOWEVER, GetEvent isn't really good to use when you have multiple windows because it waits for an event to happen. Consider, for example, your program is waiting for events to occur on 'wnd', but the user is doing all sorts of things on 'wn'. The 'wn' events would be piling up and you wouldn't be processing any of them because your program is stuck until 'wnd' gets an event.
You'll need to make a more dynamic event poller if you want this to work. One which checks events on all windows.
Basically, adding a new window adds a bunch of complexity that might not be worth it. Don't get me wrong, it's certainly doable (and once you understand what's going on, it isn't really that hard), but is it really necessary for what you want?