I'm using OpenGL ES 3.0 on Android 5.1, and am noticing the following issues. I tried to implement the game loop which does exactly 60 updates and do as many frames as it can. Everything is smooth, but the object is being rendered twice, I think due to interpolation by hardware.
If you zoom the image (click to view in separate tab) you'll see that the green square is being rendered twice. And now if I remove the catch-up code, it works correctly.
As you can see it now renders fine. Now I'll show you my game loop. I'm using GLSurfaceView
class, and doing my render in onDrawFrame
of the renderer.
double now = TimeUtils.currentTime();
if (previous == -1)
previous = now;
double delta = now - previous;
if (delta >= SECOND)
delta = frameTime;
lag += delta;
while (lag >= frameTime) // This line plays catchup.
// If commented, it works otherwise the
// artifact occurs
{
updates++;
doUpdate(frameTime);
lag -= frameTime;
}
frames++;
glClear(GL_COLOR_BUFFER_BIT);
doRender(frameTime);
if (now - lastStatsTime >= SECOND)
{
updatesPerSecond = updates;
framesPerSecond = frames;
updates = frames = 0;
lastStatsTime = now;
}
previous = now;
Is there anything that I'm doing wrong? I'm using a dynamic VBO for rendering, the lines are generated every frame and I use glBufferData
to send them to GPU. This happens every frame (This is being done for educational purpose, to learn how VBOs are streamed).
Are there any issues that I'm forgetting?