Jump to content
  • Advertisement
arrwhidev

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!