1
votes

I'm hoping someone can help me out, I'm using SFML 2.1 and when I draw my renderWindow it just keeps flickering, now I know SFML uses two buffers so i'm sure one is not getting drawn at all but I can't understand why.

Here is my loop

while(!quit)
{

    rs.Canvas.pollEvent(gameEvent);
    colour += 1;
    rs.Update(colour);

    if(gameEvent.type == sf::Event::Closed)
        quit = true;

    rs.Canvas.clear( sf::Color(colour,0,0) );

    rs.Canvas.draw( sprite );

    rs.Canvas.display();

    if(colour >= 300)
        quit = true;
}

the rs.Canvas has these set

Canvas.setVerticalSyncEnabled(true);
Canvas.setFramerateLimit(60);

Can anyone see why my renderWindow would flicker?

2
I'm not familiar with SFML, but could the flickering be caused by you clearing the canvas before drawing to it? Or is it Canvas.display() which actually draws it to the screen? - Brian Gradin
Its ok, I looked into the code and I found I was using Canvas.clear() twice, so basically it was clearing the front buffer and back buffer, so one was never set. its fine now, delete the question :) - Canvas
Could you add the solution as actual answer and accept it, so the question gets marked as solved? - Lukas

2 Answers

2
votes

From the SFML 2.0 tutorial, under the section Controlling the framerate:

Never use both setVerticalSyncEnabled and setFramerateLimit at the same time! They would badly mix and make things worse.

http://www.sfml-dev.org/tutorials/2.0/window-window.php#controlling-the-framerate

In the comments of your post, you state that you were calling clear twice on the window. This would effectively treat your window as if it were single buffered. I understand that the effect of this could create some screen tearing, but on my end I am not getting a glaring flicker effect. Make sure to remove your a call to either setting the framerate or to using the vertical sync, just to be sure.

0
votes

Basically I was calling

rs.Canvas.clear

twice. I removed the second call and everything then worked fine