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

Author Topic: SFML2 - Blinking window  (Read 3745 times)

0 Members and 1 Guest are viewing this topic.

Ekinox

  • Newbie
  • *
  • Posts: 10
    • View Profile
SFML2 - Blinking window
« on: May 03, 2011, 07:22:03 pm »
Hello !

I'm coming here because a very simple code is not working.

I simply print a graphic window, filled with red. At each display, it switchs black and red ...

The code :
Code: [Select]

sf::RenderWindow Win(sf::VideoMode::GetFullscreenModes()[0], "SFML Test");
Win.SetFramerateLimit(10);
Win.Clear(sf::Color::Red);
while (!Win.GetInput().IsKeyDown(sf::Key::Escape)) {
Win.Display();
}


Moreover, I'm not able to quit the main loop with the escape key, using this code.

What should I do ?
(I downloaded SFML2 snapshot yesterday - or the day before - and built it using CMake, and I use Visual Studio 9 2008 express edition.)

Thanks in advance,
Equinoxe

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML2 - Blinking window
« Reply #1 on: May 03, 2011, 08:05:15 pm »
You need to clear the window and process the occurred events (using sf::RenderWindow::PollEvent) in each frame of your main loop.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ekinox

  • Newbie
  • *
  • Posts: 10
    • View Profile
SFML2 - Blinking window
« Reply #2 on: May 03, 2011, 08:26:22 pm »
Thanks !

Btw that's strange, that a window has 1 frame on 2 black if the application is not cleared (I tried changing the framerate). I thought Clear was to be used only if we wanted some sprites to be removed from the window.

The same goes for Input needing PollEvent (which it btw called GetEvent in the doc), as far as SFML could maintain its own version of the event queue.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML2 - Blinking window
« Reply #3 on: May 03, 2011, 08:33:50 pm »
Quote
Btw that's strange, that a window has 1 frame on 2 black if the application is not cleared (I tried changing the framerate).

SFML uses double-bufferring, so if you only clear one buffer the other remains uninitialized, and you see it one frame on two (Display() swaps the buffers).

Quote
I thought Clear was to be used only if we wanted some sprites to be removed from the window.

Nop, Clear() must be used to restart every new frame. Real-time rendering is about rendering the whole stuff every frame, nothing is persistent in the window.

Quote
The same goes for Input needing PollEvent (which it btw called GetEvent in the doc), as far as SFML could maintain its own version of the event queue.

Yes, that's what sf::Input is for: storing events attributes so that they can be accessed at any time.
Laurent Gomila - SFML developer

Ekinox

  • Newbie
  • *
  • Posts: 10
    • View Profile
SFML2 - Blinking window
« Reply #4 on: May 04, 2011, 12:32:11 pm »
Thanks for these precisions. :D

 

anything