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

Author Topic: Blinking/shaking screen(buffer?)  (Read 2366 times)

0 Members and 1 Guest are viewing this topic.

Dper

  • Newbie
  • *
  • Posts: 4
    • View Profile
Blinking/shaking screen(buffer?)
« on: January 13, 2012, 01:03:57 am »
Hello there
Recently I've started toying with SFML and encountered problem. Hope I can get some help/explanation here.
First off I'm using SFML 2 fresh build (like 2 days old) with MinGW, win7 x64 if that matters.

I wanted to move dot around screen without removing its trail but even when its not supposed to move anymore(moved out of screen - stopped drawing) I can see whole window content blinking and dot trail "animating". It's almost as if buffers were different and were constantly swapped.
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::VideoMode Vmode(800, 600, 32);
    sf::RenderWindow Window(Vmode,"");
    sf::Vector2f ppos;
    sf::Vector2f vec;
    sf::Event Event;
    vec.x = 5;
    vec.y = -1.5;

   sf::CircleShape D;
   D.SetRadius(3.0f);
   D.SetFillColor(sf::Color(255,0,0));

    while (Window.IsOpened())
   {
      if(ppos.x+vec.x<800 && ppos.y+vec.y<600 &&(ppos.x+vec.x)>1 && (ppos.y+vec.y)>1)
      {
         ppos.x=ppos.x+vec.x;
         ppos.y=ppos.y+vec.y;
         D.SetPosition(ppos);
      }

      while (Window.PollEvent(Event))
      {
         switch (Event.Type)
         {
            case sf::Event::Closed:
               Window.Close();
               break;
            case sf::Event::KeyPressed:
               if(Event.Key.Code == sf::Keyboard::Escape)
                  Window.Close();
               break;
            case sf::Event::MouseButtonPressed:
               if(sf::Mouse::IsButtonPressed(sf::Mouse::Right))
               {
                  ppos.x=Event.MouseButton.X;
                  ppos.y=Event.MouseButton.Y;
               }
               break;
            default:
               break;
         }
      }
      Window.Draw(D);
      Window.Display();
   }
   return 0;
}


any idea what is real cause and how to prevent it?

Haikarainen

  • Guest
Blinking/shaking screen(buffer?)
« Reply #1 on: January 13, 2012, 06:28:58 am »
You HAVE to clear the screen, or there WILL be artifacts. Try drawing to a RenderTexture and draw that texture instead.

Something like;
Code: [Select]
sf::RenderTexture Meh(...initialize...);
Meh.Clear();


then draw on it;
Code: [Select]
Meh.Draw(Dot);
Meh.Display();


Then draw Meh onto window;
Code: [Select]
Window.Draw(Meh);

Dper

  • Newbie
  • *
  • Posts: 4
    • View Profile
Blinking/shaking screen(buffer?)
« Reply #2 on: January 13, 2012, 02:25:48 pm »
Thanks got it working now
Although couldn't get
Code: [Select]
Window.Draw(Meh); to work, used texture=>sprite=>window instead

 

anything