# OpenGL Why is my simple OpenGL engine jittering/skiping frames?

## Recommended Posts

I think you might have misunderstood a little, the game loop you have in the master branch is already correct and works as it should, you only need to replace:

engine.render();
//with
engine.render( accumulator / DT );

I tried cloning your git and tested it myself using the game loop below, it ran very smooth and jitter-free.

float accumulator = 0.0f;
//long currentTime = System.currentTimeMillis();
double currentTime = GLFW.glfwGetTime();

while (isRunning && !window.windowShouldClose()) {
// long newTime = System.currentTimeMillis();
// float frameTime = (newTime - currentTime) / 1000.0f;
double newTime = GLFW.glfwGetTime();
double frameTime = newTime - currentTime;

// Avoid spiral of death
if (frameTime > 0.25f) frameTime = 0.25f;

currentTime = newTime;
accumulator += frameTime;

// Logic update
while (accumulator >= DT)  {
accumulator -= DT;
engine.update(DT);
}

engine.render(accumulator / DT);
}

Btw I took the liberty to replace System.currentTimeMillis() with GLFW.glfwGetTime() in the code above for best timer accuracy.

##### Share on other sites
3 hours ago, magn919 said:

I think you might have misunderstood a little, the game loop you have in the master branch is already correct and works as it should, you only need to replace:

Btw I took the liberty to replace System.currentTimeMillis() with GLFW.glfwGetTime() in the code above for best timer accuracy.

Thanks @magn919 To be clear, you took the loop from master branch with the modifications you have shown above and used the interpolation code from the fix_gameloop branch? Did you also disable vsync?

I've just done this (pushed to fix_gameloop branch) it's not smooth jittering etc. Perhaps something strange is happening on my machine? I just tried the code on my laptop, it seemed a bit better  - the framerate was roughly the same - but I still saw some jittering and the odd frame skipping.

Did you do anything else differently?

##### Share on other sites

I basically just copied the game loop from the master branch to the fix_gameloop, with those modifications(The timing and the interpolation).

It's the same after checking out your latest commit, it runs perfectly smooth for me. I'm not sure why the problem keeps persisting for you, but If it helps you locating the issue, I'm running Windows 10 on a high end gaming desktop pc, fps caps at roughly 4500 without vsync and 60hz with v-sync, no visual differences or issues.
I have also tried running it on my older Windows 10 laptop where it too runs smoothly, fps caps at about 700 without v-sync and 60 with v-sync, also no visual differences or issues.

Just taking a random guess here since I noticed that you are using the macos natives, could the issue be OS or driver related?

##### Share on other sites
Posted (edited)
On 7/26/2019 at 12:14 AM, magn919 said:

I basically just copied the game loop from the master branch to the fix_gameloop, with those modifications(The timing and the interpolation).

It's the same after checking out your latest commit, it runs perfectly smooth for me. I'm not sure why the problem keeps persisting for you, but If it helps you locating the issue, I'm running Windows 10 on a high end gaming desktop pc, fps caps at roughly 4500 without vsync and 60hz with v-sync, no visual differences or issues.
I have also tried running it on my older Windows 10 laptop where it too runs smoothly, fps caps at about 700 without v-sync and 60 with v-sync, also no visual differences or issues.

Just taking a random guess here since I noticed that you are using the macos natives, could the issue be OS or driver related?

Thanks for trying that out for me - really appreciate it.

This is very odd... I managed to run the code on an older Windows 7 machine and I experienced the same jitter with uncapped fps (forgot to try with vsync). My main mac desktop is still jittering with both vsync and uncapped fps. I did try the code on a slightly newer mac laptop and with uncapped fps I still experienced jitter but with vsync on it was smooth - first time I've seen it like this.

Can't work out any pattern to this.

All I know is that vsync was smooth on a newer mac and everything worked for your on your faster machines. It seems that the jitter is only obvious on 'slower' machines. But none of these machines are really 'slow' and I'm only bouncing one quad left and right.

All machines can cope with the framerate easily so I'm a bit confused/lost. Very frustrating - I just want to start on the actual game but I'm apprehensive with the current performance.

I'll post back if I work it out.

(edit) Oh - I also updated all the dependencies to latest and that didn't help either!

Edited by arrwhidev

##### Share on other sites

Might seem a weird test but set your updated per second to 40 and tell me if it works.

I've the same issue in my game engine but currently simplified to a FPS centric game loop.

A few linkk that may help:
http://entropyinteractive.com/2011/02/game-engine-design-the-game-loop/
http://gameprogrammingpatterns.com/game-loop.html
https://stackoverflow.com/questions/18283199/java-main-game-loop

## Create an account

Register a new account

• 9
• 12
• 15
• 12
• 24