Multiple RenderWindows in SFML

I've been playing around with RenderWindows in SFML a little, not really having much of an idea what I'm doing.

If I open two windows (a top and a bottom) and close the top one, the portion of the top window that overlapped the bottom window remains visible. Here's a screenshot:

http://i92.photobucket.com/albums/l28/erikhasissues/screen.png

Anyone know why?

Weirdly, if I make the bottom window active and close it first, it vanishes completely as expected.

Again, I have no idea what I'm doing.
Here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "stdafx.h"
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"


int _tmain(int argc, _TCHAR* argv[])
{
		    
	    sf::VideoMode VTMode(600, 400, 32);
	    sf::VideoMode VBMode(800, 300, 32);
	    
	    sf::RenderWindow BotWin(VBMode, "This is the bottom window.");
	    sf::RenderWindow TopWin(VTMode, "This is the top window.");

	    sf::Shape Ball=sf::Shape::Circle (0,0,25,sf::Color(0,0,200));
	    
		int x, y;
		x=255; y=100;
		int z=150;
		

	    while (TopWin.IsOpened()||BotWin.IsOpened())
	    {

	       sf::Event A;
	       TopWin.GetEvent(A);
	            
		   if (A.Type==sf::Event::Closed)TopWin.Close();
			  if (A.Type==sf::Event::MouseEntered) {x=255;y=100;}
			  if (A.Type==sf::Event::MouseLeft) {x=0;y=255;}
	                  
	       BotWin.GetEvent(A);
		   if (A.Type==sf::Event::Closed) BotWin.Close();
		
			
		TopWin.Display();
		BotWin.Display();

                BotWin.Clear(sf::Color(255, 0, 255));
		TopWin.Clear(sf::Color(x, y, 0));

		Ball.SetPosition(z,150);
		TopWin.Draw(Ball);
		z++; 
                sf::Sleep(0.03f);
					
		}
	 
	    return 0;
}
Last edited on
The only thing I can think is that you are potentially processing bad events. GetEvent will return false if there were no events to process, in which case you shouldn't be processing the event. Put your GetEvent calls in an if statement:

1
2
3
4
5
6
7
8
9
if(TopWin.GetEvent(A))
{
  if(A.Type  ...
}

if(BotWin.GetEvent(A))
{
  ...
}


It also doesn't make sense to clear/display TopWin or BotWin if they're closed.
Ok, thanks Disch. I'll play with it more.
Changed per your suggestion, but I'm getting the same results:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stdafx.h"
#include "SFML/Graphics.hpp"


int _tmain(int argc, _TCHAR* argv[])
{
		    
	        sf::VideoMode VTMode(600, 400, 32);
		sf::VideoMode VBMode(800, 300, 32);
	    
	        sf::RenderWindow BotWin(VBMode, "This is the bottom window.");
		sf::RenderWindow TopWin(VTMode, "This is the top window.");

		sf::Shape Ball=sf::Shape::Circle (0,0,25,sf::Color(0,0,200));
		

		int x, y;
		x=255; y=100;
		int z=150;
		

	    while (TopWin.IsOpened()||BotWin.IsOpened())
	    {

	       sf::Event A;

	       if (TopWin.GetEvent(A)) 
                       {
	            
		                 if (A.Type==sf::Event::Closed)TopWin.Close();
			         if (A.Type==sf::Event::MouseEntered) {x=255;y=100;}
			         if (A.Type==sf::Event::MouseLeft) {x=0;y=255;}
	               }


		if (BotWin.GetEvent(A))
		            if (A.Type==sf::Event::Closed) BotWin.Close();
		
			
		
		if (BotWin.IsOpened()) 
			{
				BotWin.Display();
                                BotWin.Clear(sf::Color(255, 0, 255));
		        }



		if (TopWin.IsOpened()) 
			{
				TopWin.Display();
		                TopWin.Clear(sf::Color(x, y, 0));
                                Ball.SetPosition(z,150);
		                TopWin.Draw(Ball);
		                z++; 
				sf::Sleep(0.03f);
		        }
					
		}
	 
	return 0;
}
Sorry, I'm out of ideas.

It works for me just fine with SFML 2.0 (after making the necessary adjustments)
(after making the necessary adjustments)


Do you mean your previous suggestions which I implemented?

Also, I didn't mention this before but I'm using 1.6 (headers, libraries and external libraries) pack for Visual C++ 2008. I'm using it in VC++ 2010 with .dll files downloaded from this site:

http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-The-Introduction.aspx

which are allegedly configured to play nice with VC2010.


Last edited on
And do you mind if I ask what you're using for an IDE?
I'm starting to think it might have to do with those .DLLs.
Last edited on
Do you mean your previous suggestions which I implemented?


No, I mean changing some things to make it work with SFML2. SFML2's Sleep takes time in ms, not in seconds, and also GetEvent became PollEvent (or something similar).

If the DLLs were built to work with VC2010 then you're probably OK. If it was an issue with the DLL it's far more likely that the program would be crashing or failing to run than anything else.

I really don't have any other ideas =(

I use VC++ Express 2010
...and you are able to close the top window (the one with the circle) and it disappears completely leaving the bottom window contents entirely visible?

It must be something with my setup or computer.

Yep. Closing the top window shows a fully pink bottom window.

Might be worth posting on the SFML forums. Laurent might have more ideas.
I did, and no dice so far.
But it's only been up there for a day, which might only be a few hours in French-time. :)


Ok, so should I maybe try a different IDE or media library?

or is there a book i can read on this?

or somebody anywhere that knows of somebody else anywhere that knows something about this?

I really want to learn....

What about switching to VS2008?

Last edited on
closed account (S6k9GNh0)
What is _tmain?
the default main function name in VS10.
it's a Microsoft extension that allows for unicode.
Last edited on
closed account (S6k9GNh0)
EDIT: I hate Microsoft.
Last edited on
i don't get it- why even post that?
closed account (S6k9GNh0)
Because you'll receive better help about SFML on the SFML forum. That and you use a VC++ specific convention that simply annihilates that which is portable code.
Last edited on
you'll receive better help about SFML on the SFML forum. That and you use a VC++ specific convention that simply annihilates that which is portable code.


Right. However, this thread is about a specific problem, more than likely a config issue, that has nothing to do with the one Microsoftism that you point out. And judging by the fact that the same code works fine for others in their environment, the fact that I've already mentioned having posted on the SFML board, the fact that I've uninstalled, re-downloaded, and reinstalled SFML and VS several times and reformatted my hard drive in the past two days trying to figure this out, leads me to the vague hunch that this may not be explicitly an SFML issue.

But perhaps I'm being presumptuous, in which case my thread on the SFML board isn't going anywhere (except maybe to the third page). :)
closed account (S6k9GNh0)
I'm not sure 1.6 had proper multi-window support. I know for a fact 2.0 does though. Example works fine here although I had to change GetEvent to PollEvent
Last edited on
Topic archived. No new replies allowed.