Jump to content
  • Advertisement

arrwhidev

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

2 Neutral

About arrwhidev

  • Rank
    Newbie

Personal Information

  • Interests
    Audio
    Programming

Social

  • Github
    arrwhidev

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. 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!
  2. 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?
  3. I've tweaked a bit as you say but I'm still in the same position. It's kinda jittery entirely smooth. Everything is pushed to branch, but I'll post here for ease. Game loop: (https://github.com/arrwhidev/opengl-game/blob/fix_gameloop/src/main/java/com/arrwhidev/opengl/engine/loop/GameLoop.java) private static final int UPDATES_PER_SECOND = 30; private static final double NS_PER_SECOND = 1000000000.0; private static final float NS_BETWEEN_TICKS = (float) NS_PER_SECOND / UPDATES_PER_SECOND; private static final float DT = 1.0f / UPDATES_PER_SECOND; private long now() { return System.nanoTime(); } public void run(Window window) { double nextUpdate = now(); float interpolation; while (isRunning && !window.windowShouldClose()) { long t = now(); while(t >= nextUpdate) { engine.update(DT); nextUpdate += NS_BETWEEN_TICKS; updates++; } interpolation = (float) (t + NS_BETWEEN_TICKS - nextUpdate) / NS_BETWEEN_TICKS; if (interpolation > 1) interpolation = 1; else if (interpolation < 0) interpolation = 0; engine.render(interpolation); } } Interpolation: (https://github.com/arrwhidev/opengl-game/blob/fix_gameloop/src/main/java/com/arrwhidev/opengl/game/ecs/misc/Transformation.java) float newX = ((position.x() - position.prevX()) * interp) + position.x(); float newY = ((position.y() - position.prevY()) * interp) + position.y(); return MODEL_VIEW_MATRIX.identity() .mul(camera.getProjection()) .translate(newX, newY, 0) .scale(position.getScale()); On my machine that runs at 30 update/sec and around 700 frames/sec. I've uploaded another video to show how it looks for me. I feel like I've got everything right. But it's definitely not smooth: https://raw.githubusercontent.com/arrwhidev/opengl-game/fix_gameloop/jitter2.mov Thanks again!
  4. Final update before bed, I realized vsync was ALWAYS on. I've turned it off now. Even though I'm updating at 30hz, rendering at something like 400hz and interpolating, it's now worse that it ever was, jitter and frame skipping all over the place. All this is visible in the fix_gameloop branch. Dammit!
  5. I'm using VAOs/VBOs to render. When multiple quads are visible, they all jitter at the same time, so it does seem like it's related to the game loop, as @magn919 wrote. V-sync is enabled, I tried turning it off but it didn't appear to improve the overall smoothness and jitters still happened too. Thanks for your detailed response @magn919. What you've said makes a lot of sense and I agree that this is probably the cause. I re-wrote my loop to use a fixed update rate with variable frame rate, setting the update to 30 caused what I would expect; the movement became very choppy. The jumps between updates were clear. I upped the rate to 300 and became smoother. Then I implemented a very basic interpolation, by guessing the position between old and new position using the interpolation value (between 0 and 1). It did smooth things out - still isn't 100% perfect though - still seeing frame skips sometimes - it seems less frequent though. I've been staring at this bouncing square for so long now that I don't even know what looks good anymore haha! Also, my simple interpolation isn't very smart, it only works for position, and linearly. If entities were to accelerate, this code would predict too much or too little. Also, if entities were not moving, but scaling, or rotating, it would do nothing. This means I need to duplicate all my coding efforts now; as I add things into the game logic (such as scaling and rotation), I need to remember to replicate these in my interpolation code. Is this correct? It feels wrong and a bit smelly. However, I can't think of any alternatives. BTW - I pushed changes to a new branch; https://github.com/arrwhidev/opengl-game/tree/fix_gameloop Thanks again.
  6. Hi all, I've built a very basic engine & game (not really a game yet) in Java to learn OpenGL. I didn't use C++ as I wanted to learn one thing at a time & I'm already very comfortable with Java. I've used LWJGL just as an OpenGL wrapper, I've not used anything else it offers - I wanted to learn & write everything from first principals. Anyway, it's a very simple game loop that renders a single square which bounces around the screen linearly. Clicking in the window will create another square with a random size/colour/velocity at the cursor location. Now to my question, I observed that every now and again the square has some serious jitter for a few seconds - looks like frames skipping or something. Also, generally, the square does not seem to move very smoothly, even though it's running at 60 FPS - increasing this does not seem to improve things. What I've found; Whether I have one square or 200 squares the performance remains constant and the problems still exist. The issue is as obvious with one as it is with many. There are no obvious memory leaks or CPU issues - I attached a profiler, everything looks OK. It's not GC - again, I can see this in the profiler. I experience jitter GC is not occurring, so I can rule that out too. I recorded a video to demonstrate the issue (it can be clearly seen at 16 seconds): https://github.com/arrwhidev/opengl-game/blob/master/jitter.mov The code is on GitHub and pretty easy to run, details in README: https://github.com/arrwhidev/opengl-game Any ideas where to start? Any clues/ideas? Many thanks!
  • 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!