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

Author Topic: Beginner question about RenderWindow::Display()  (Read 2058 times)

0 Members and 1 Guest are viewing this topic.

Phalanx

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://gameandcode.com
Beginner question about RenderWindow::Display()
« on: November 26, 2011, 08:26:30 pm »
I'm having trouble understanding the core concept of a game loop, and when the display actually happens. Could someone explain why this code (using SFML 2.0) successfully pops up a blank window:

Code: [Select]
void Game::Start(void) {    
    _mainWindow.Create(sf::VideoMode(1024, 768), "Otto");
    _mainWindow.SetFramerateLimit(60);

   
    while (!IsExiting()) {
        sf::Event currentEvent;
        while (_mainWindow.PollEvent(currentEvent)) {        
           
        }
        _mainWindow.Clear(sf::Color(0,0,0));
        _mainWindow.Display();
    }
   
    _mainWindow.Close();
}


But this code does not:

Code: [Select]
void Game::Start(void) {    
    _mainWindow.Create(sf::VideoMode(1024, 768), "Otto");
    _mainWindow.SetFramerateLimit(60);

   
    while (!IsExiting()) {
        _mainWindow.Clear(sf::Color(0,0,0));
        _mainWindow.Display();
    }
   
    _mainWindow.Close();
}


All that I removed is the event handling. Is there some tie in at the SFML level that actually triggers the display, or does the display happen immediately when .Display() is called?

Thanks for any help!
Wannabe Game Developer
Game & Code

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Beginner question about RenderWindow::Display()
« Reply #1 on: November 26, 2011, 09:23:40 pm »
Maybe IsExiting() is returning true?

Phalanx

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://gameandcode.com
Beginner question about RenderWindow::Display()
« Reply #2 on: November 26, 2011, 09:45:01 pm »
I'm still getting the same behavior even if I use:

Code: [Select]
while(true) {

}


Edit - Actually just created a blank project using the SFML template, and removed the lines under the //Process events comment -- same behavior occurred. So, nothing in my app logic is getting in the way. I just don't understand the tie in between events and display.
Wannabe Game Developer
Game & Code

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Beginner question about RenderWindow::Display()
« Reply #3 on: November 26, 2011, 11:14:14 pm »
In Windows, iirc, there is a render event that isn't exposed to the public by SFML, but is handled so that OpenGL rendering can work. I haven't work with Windows + OpenGL in a long time though, so don't quote me on that.
I use the latest build of SFML2

kolofsson

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Beginner question about RenderWindow::Display()
« Reply #4 on: November 27, 2011, 12:33:05 am »
I think if you do not handle all events, the window will freeze.

Phalanx

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://gameandcode.com
Beginner question about RenderWindow::Display()
« Reply #5 on: November 27, 2011, 01:01:06 am »
That seems like the case. If anyone knows why it is, I would love to know the inner workings. The sample code is run on OS X Lion and built with Xcode btw.
Wannabe Game Developer
Game & Code

 

anything