SFML community forums

General => General discussions => Topic started by: armage on February 19, 2008, 08:16:50 pm

Title: screen flicker - vsync or double buffering
Post by: armage on February 19, 2008, 08:16:50 pm
Hi,

My screen has a slight flicker due to the difference in refresh rates when I alternate the display of two sprites. This makes the rendering look a bit choppy.

How do I turn on vsync?

Some people use double buffering, check out this link
http://www.idevgames.com/forum/showthread.php?t=6750&page=2
http://www.esreality.com/?a=longpost&id=522789&page=1
Title: screen flicker - vsync or double buffering
Post by: dabo on February 19, 2008, 08:52:12 pm
Code: [Select]
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
App.UseVerticalSync(true);
Title: screen flicker - vsync or double buffering
Post by: armage on February 19, 2008, 09:27:22 pm
Thank you for your reponse. I tried your suggestion but there is no response.

How do I enable double buffering?
Title: screen flicker - vsync or double buffering
Post by: zarka on February 19, 2008, 09:58:41 pm
i belive SFML uses double buffering by default ...

and if UseVerticalSync(true) didn't do anything you have most likely disabled v-sync in your graphics card drivers. You will probably be able to change v-sync settings in the settings program for your graphics driver.
Title: screen flicker - vsync or double buffering
Post by: armage on February 19, 2008, 10:20:06 pm
I tried looking up some GLUT double buffering examples. It is working on my computer with no flicker and seems pretty smooth.

In GLUT there is a way to initialize double buffering. How do I code double buffering anyway?
Title: screen flicker - vsync or double buffering
Post by: armage on February 19, 2008, 10:51:23 pm
Just one question, when I do

Code: [Select]

sf::RenderWindow App;

App.Create(sf::VideoMode(1280, 768, 32), "SFML Window",sf::Style::Fullscreen, 4);


Is this using the win32?

Meaning, did stuff like:
Code: [Select]
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
              PFD_DOUBLEBUFFER;
SwapBuffers( hDC );
Title: screen flicker - vsync or double buffering
Post by: Laurent on February 20, 2008, 02:37:18 am
You shouldn't care about internal behaviour of SFML. Of course it's using double-buffering, and of course it's using all the Win32 stuff it needs.

You should rather show us your code, and if possible, upload a compiled version of your app so that we can see what happens.
Title: I still get a bit of flicker....
Post by: retrogamer4ever on May 27, 2009, 07:52:33 pm
I still see a bit of flickering, or it could just be that i am crazy... Here is my code
Code: [Select]

#include "stdafx.h"
#include "sfml.h"

using namespace sf;

int main()
{
// Create the main window
RenderWindow App(VideoMode(616, 387, 32), "SFML Window");
App.UseVerticalSync(true);

Image img_background;
if(!img_background.LoadFromFile("c://background.png"))
return -1;

Image img_ball;
if(!img_ball.LoadFromFile("c://ball.png"))
return -1;

Sprite background(img_background);
Sprite ball(img_ball);

ball.SetY(325);
   
while (App.IsOpened())
{    
Event Event;

while (App.GetEvent(Event))
{
if (Event.Type == Event::Closed)
App.Close();

if ((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape))
App.Close();
}

if (App.GetInput().IsKeyDown(Key::Right)) ball.Move(100, 0);
if (App.GetInput().IsKeyDown(Key::Left))  ball.Move(-100, 0);

App.Clear();
App.Draw(background);
App.Draw(ball);

App.Display();
}

    return EXIT_SUCCESS;
}



I basically just had two simple images, one background image colored red that was the size of the window, and a white ball image that I moved back and forth...  The white ball tends to flicker sometimes though.  Any idea why it would?  I have solved this flickering issue in the past by just preforming some double buffering, but doesn't seem like you can easily add sprites with in sprites.  Any idea what I might be doing wrong?  Or is the flickering all in my head :-P