This one runs so smooth but that's probably because it renders 6k times a second.
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(1280, 720), "Stutter");
sf::Event event;
sf::Clock clock;
float accumulator = 0.0f, delta = 1.0f / 125.0f;
//window.setVerticalSyncEnabled(true);
sf::RectangleShape rect(sf::Vector2f(5.0f, 720.0f));
float pos = 0.0f;
while(window.isOpen()) {
accumulator += clock.restart().asSeconds();
//while(accumulator > delta) {
accumulator -= delta;
// Poll Events
while(window.pollEvent(event)) if(event.type == sf::Event::Closed) window.close();
// Update
if((pos += 20.0f*delta) > 1280.0f) { pos = 0.0f; }
//}
// Set position to interpolated position
rect.setPosition(pos, 0.0f);
// Render
window.clear();
window.draw(rect);
window.display();
}
return 0;
}
Might sound stupid, but what happens if you're sleeping for 1 millisecond at the end of your update loop? Does that change anything?
Also which graphics card are you running and what's your actual FPS? Do FPS change when the stuttering happens or is it stable? How about the number of update per second in these situations?
Wow... Having
sf::sleep(sf::milliseconds(1));
after the .display() helps to make it smooth like I open the program, line is shaky for like 0.3-0.4 seconds, then it becomes smooth and keeps being smooth. Yet it shakes when I shake my mouse
(1000 Hz polling rate mouse and I don't have this issue in CS:GO)
Nvidia GTX 770 and 144 Hz monitor I have so I can see the smallest difference.
Fraps says 144 FPS, when I shake the mouse, line shakes and FPS becomes 143.
Edit: It is so weird that I removed sleep(1) and it is still smooth now. Sometimes it stutters, sometimes it does not. Very confusing.