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

Author Topic: Problems Making Multiple RenderWindows Work  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

erikn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems Making Multiple RenderWindows Work
« on: January 03, 2012, 04:01:56 pm »
Hi.
First post here so greetings all.   :)

Very new to SFML (yesterday) and just getting back into programming after a long hiatus (decades).  

I'm using SFML 1.6 (Headers, Libraries, and External Libraries Visual C++ 2008 pack) in VS2010 Express with C++, using .dll files downloaded from here:
http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-The-Introduction.aspx
which are allegedly configured to agree with VS2010.


I've been playing around with RenderWindows 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/erikhasissue/screen.png

Anyone know why?

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

Allow me to emphasize once more, I have no idea what I'm doing.
Here's my code:

Code: [Select]
#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;
}

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Problems Making Multiple RenderWindows Work
« Reply #1 on: January 03, 2012, 05:05:01 pm »
After a quick look I notice two things:

1) Shouldn't u use while instead of if at the GetEvent functions?
2) First call Clear and then Display
TGUI: C++ SFML GUI

erikn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems Making Multiple RenderWindows Work
« Reply #2 on: January 03, 2012, 05:30:21 pm »
Quote from: "texus"
1) Shouldn't u use while instead of if at the GetEvent functions?
2) First call Clear and then Display


Thanks texus, but neither suggestion fixed the problem.

Though I've seen while used in single-window example code that others have posted, I guess I don't understand logically why it would be advantageous in this particular setting, with both windows being checked continuously etc.

As for the order of Clear() and Display(), when I switched it for TopWin, not only did it not solve my problem, but also the Shape::Circle was no longer visible.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Problems Making Multiple RenderWindows Work
« Reply #3 on: January 03, 2012, 05:43:23 pm »
If you use "if" then you will only handle ONE event per frame. When using "while" you will handle ALL events of the window and then continue with drawing.

Are you first calling Clear, then Draw and then Display?
TGUI: C++ SFML GUI

erikn

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problems Making Multiple RenderWindows Work
« Reply #4 on: January 03, 2012, 06:07:30 pm »
Quote from: "texus"
Are you first calling Clear, then Draw and then Display?


Oops nope. That brings my circle back.

But still doesn't solve the original problem...

At this point I'm thinking it might have something to do with those configged .DLLs....