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

Author Topic: Flickering issue  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

ghzmdr

  • Newbie
  • *
  • Posts: 11
    • View Profile
Flickering issue
« on: March 16, 2015, 03:25:53 am »
Hi everyone, I'm building a game prototype and there's an issue I can't get rid of.
Basically some sprites get drawn with a delay and out of place, I don't know what's the matter with them, I mean, I draw them in a simple loop like this:

void Zone::draw()
{  
    context.window->setView(worldView);    

    for (auto &tile : bgLayer)
    {
        if (isInBounds(tile))
            context.window->draw(tile);
    }

    context.window->draw(player);
}
 
where bgLayer is a vector of sf::Sprite. These are positioned once and do not get moved.
The window is cleared once in the main loop's render()

void Application::render()
{
    window.clear(sf::Color::Black);

    stateStack.draw();

    window.setView(window.getDefaultView());
    window.display();
}

 

There is no other window manipulation or drawing.

To better describe the issue I've uploaded a screen on youtube


Basically it seems like things get drawn out of position when the view moves, causing a strange flickering.

Anyone has an Idea about how to fix this? If you need to see more code just tell, I didn't want to clutter the post and I tought this could be a simple issue for someone more experieced. Thanks in advance!

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Flickering issue
« Reply #1 on: March 16, 2015, 04:35:14 am »
I'm not sure what we're supposed to see.
Are you referring to screen tearing? If so, try enabling vertical synchronization.

ghzmdr

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Flickering issue
« Reply #2 on: March 16, 2015, 05:46:46 am »
Gosh that's really hard to see because youtube lowers video quality... I'll try to descibe the issue better, also there's another upload on yt and an mp4 as an attachment.


Some tiles are drawn out of place, I don't know how to call this, It's like if there was a line 100px or so from the bottom of the window, every tile under that line is drawn out of place when the view moves.

Like if there was some kind of lag in the drawing process. This appens only when the view moves (it follows player position) higher speed = more lag and more offset in the drawning.

I'm not doing anything fancy and this never happened in other games which share basic code with this one. Also it does not only happen with tiles, but with every sprite I draw. Tried running both with internal intel GPU and Nvidia, unfortunately I can't test this on other machines or Windows/Mac so I can't event figure out if it's my platform (ArchLinux 64 bit, intel/nvidia drivers, latest sfml binaries).

I think it could have more to do with the view moving than with the textures because I tried changing pngs, drawing only one large sprite instead of multiple tiles in a loop, enabling/disabling vsync and texture smoothing... This is a nasty one, I can't figure out how to debug it because sprites position it's ok It's like there were 2 buffers, one on top of that line and another on the bottom...

Try looking at the far left/right of the screen, where the tiles end, you can see some of them are out of place, with an offset of like 20px on the opposite direction.

Also here's the class which is causing this madness.

(click to show/hide)
« Last Edit: March 16, 2015, 05:57:20 am by ghzmdr »

ghzmdr

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Flickering issue
« Reply #3 on: March 16, 2015, 06:15:10 am »
Holy crap... It was due to XFCE's compositing nothing to do with code or SFML... I'm thiking about suing 'em for the night I've spent on this  :o :o :o :o

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Flickering issue
« Reply #4 on: March 16, 2015, 02:26:18 pm »
Holy crap... It was due to XFCE's compositing nothing to do with code or SFML... I'm thiking about suing 'em for the night I've spent on this  :o :o :o :o
lol you'd lose.  That aside it is good you found out what was going on. :)
I have many ideas but need the help of others to find way to make use of them.

 

anything