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

Author Topic: Vsync causing strange jitter effect (SFML 2.0)  (Read 3823 times)

0 Members and 1 Guest are viewing this topic.

schmitty

  • Newbie
  • *
  • Posts: 6
    • View Profile
Vsync causing strange jitter effect (SFML 2.0)
« on: November 05, 2012, 07:09:27 pm »
I am having some weird results when vSync is enabled in my 2D platformer.

I am using impulse based framerate independent movement for the entities in my 2D platformer game. I also have the view follow the player by setting its center to the player's position each frame. When vSync is off and the game is running ~1000 fps, everything is fine and the movement is smooth. When I enable vSync and the framerate locks at ~60 fps the player seems to jitter back-and-forth 1 pixel once every 10 frames or so. The players movement speed is still correct, and all other entities don't jitter, but for some reason the player experiences a slight jitter.

Any help troubleshooting the source of the problem would be greatly appreciated. I've tested and the view center is equal to the players position each frame, so there is no strange off-by-one frame lag or anything.

Another strange thing possibly worth mentioning is that the player has a weapon that is also set to the player position each frame. This weapon does not experience the jitter effect when vSync is enabled, only the player does.

Thanks!
« Last Edit: November 05, 2012, 08:23:20 pm by schmitty »

ncsu121978

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Vsync causing strange jitter effect (SFML 2.0)
« Reply #1 on: March 05, 2014, 05:27:39 am »
I know this topic is really old but I was doing some searching on an issue I am having and this post describes it perfectly.  And since I didn't see an answer/reply to this I am hoping that maybe the original poster came up with a solution or someone else can point me in the right direction.

I almost think it is some kind of issue with my video card (Geforce GTX 560M) driver issue but the driver is very up to date or maybe some setting with the OS (Windows 7). 

I have no issue using SDL2 program structured identical except using SDL2 for rendering instead of SFML2.  Now I really, really want to use SFML2 instead of SDL2 but I need to figure out this jitter.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Vsync causing strange jitter effect (SFML 2.0)
« Reply #2 on: March 05, 2014, 08:40:06 am »
As for about any other post on forum: Please provide a minimal and complete example that reproduces the problem. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ncsu121978

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Vsync causing strange jitter effect (SFML 2.0)
« Reply #3 on: March 05, 2014, 02:46:57 pm »
#include <SFML/Graphics.hpp>


#ifdef _DEBUG
        #pragma comment(lib, "sfml-system-d.lib")
        #pragma comment(lib, "sfml-window-d.lib")
        #pragma comment(lib, "sfml-graphics-d.lib")
#else
        #pragma comment(lib, "sfml-system.lib")
        #pragma comment(lib, "sfml-window.lib")
        #pragma comment(lib, "sfml-graphics.lib")
#endif

int main(int argc, char** argv)
{
        sf::VideoMode video_mode(1280, 720);
        sf::RenderWindow rw(video_mode, "Title", sf::Style::Close |sf::Style::Titlebar);
        rw.setVerticalSyncEnabled(true);

        sf::RectangleShape rs;
        rs.setSize(sf::Vector2f(100, 100));
        rs.setPosition(50.0f, 50.0f);
        rs.setFillColor(sf::Color::Red);
        rs.setOutlineColor(sf::Color::Blue);
        rs.setOutlineThickness(2.0f);


        sf::Event e;
        bool running = true;

        while (running)
        {
                while (rw.pollEvent(e))
                {
                        if (e.type == sf::Event::Closed)
                        {
                                running = false;
                        }
                }

                // update
                rs.move(2.0f, 0.0f);

                // render
                rw.clear();

                rw.draw(rs);

                rw.display();
        }
}
 

This is the minimal code to reproduce the problem.  As I said, it smoothly moves for 1-2 seconds then seems to jump backwards for one frame then forwards again.  I have is vsync so it will stay with the 60fps but even if there is a slightly longer frame time, then it wouldnt move backwards though.  And I can take the same exact program here and convert it to use SDL for rendering and have no issues.  Now I understand SDL uses DirectX as its backend on Windows which is why I think it may just be an OpenGL issue on my laptop.

Unless I am really doing something wrong, but I don't believe I am, then this makes SFML unusable for me as I cannot get smooth movements which is unfortunate because I love SFML.  And I dont believe it is an issue with SFML itself really since I dont see alot of people mentioning this problem on the boards or on google.

I should mention that i have used the .NET binding of SFML with C# with the same issue.

Insentience

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Vsync causing strange jitter effect (SFML 2.0)
« Reply #4 on: April 30, 2014, 04:17:40 am »
I'm bumping this because this issue exists in 2.1 as well, and is really irritating

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Vsync causing strange jitter effect (SFML 2.0)
« Reply #5 on: April 30, 2014, 04:21:14 am »
What makes you think VSync will cause smooth FPS? Instead do it right and measure the delta time and take that into account when doing movement.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything