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

Author Topic: Problem with RenderWindow::Clear() (Maybe a bug)  (Read 1900 times)

0 Members and 1 Guest are viewing this topic.

Uzaku

  • Newbie
  • *
  • Posts: 8
    • View Profile
Problem with RenderWindow::Clear() (Maybe a bug)
« on: April 22, 2011, 08:44:30 pm »
Hi,
after hours of searching within my code I decided to make a minimal sample to find the Error. And I think I found a Bug.

When I run this code, and press the A-Key, my Window starts flickering between black and the choosen color.

And here is a DownloadLink to a zip archiv with all files: https://rapidshare.com/files/458689578/SFMLBug.zip

Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <SFML/Graphics.hpp>
#include <list>


int WINAPI WinMain(HINSTANCE d1, HINSTANCE d2, LPSTR d3, int d4)
{
sf::RenderWindow *W = new sf::RenderWindow(sf::VideoMode(1024, 768, 32), "Test Window");
sf::Image I1, I2, I3, I4;

I1.LoadFromFile("Images\\CreateNetGame.png");
I2.LoadFromFile("Images\\Exit.png");
I3.LoadFromFile("Images\\JoinNetgame.png");
I4.LoadFromFile("Images\\Start.png");

sf::Sprite S1(I1, sf::Vector2f(0, 0)), S2(I2, sf::Vector2f(0, 200)), S3(I3, sf::Vector2f(0, 400)), S4(I4, sf::Vector2f(0, 600));

while (W->IsOpened())
{
// Process events
sf::Event Event;
while (W->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
W->Close();

if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::A)
W->Clear(sf::Color(255, 0, 255));
}

W->Draw(S1);
W->Draw(S2);
W->Draw(S3);
W->Draw(S4);

W->Display();
}

return 0;
}


greetings Uzaku

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with RenderWindow::Clear() (Maybe a bug)
« Reply #1 on: April 22, 2011, 09:07:41 pm »
That's because SFML uses double-buffering. So if you clear once instead of every frame, only one of the two internal buffers will have the chosen color, and the other will keep the default one (black, in your case). And everytime you call Display() the buffers are switched, that's why you see it flickering.

So you must call Clear() everytime.
Laurent Gomila - SFML developer

Uzaku

  • Newbie
  • *
  • Posts: 8
    • View Profile
Problem with RenderWindow::Clear() (Maybe a bug)
« Reply #2 on: April 22, 2011, 09:31:00 pm »
Oh, Im sorry for thinking it was a bug.
Ty for the quick support :)

 

anything