4
\$\begingroup\$

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.

Error image

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.

Correct image

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?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If you zoom the second image - you can see that green square rendered twice and on it to, so probably you have two draw calls for your green square...

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Exactly yes! Dunno why I missed this thing, but the surface view is calling the onSurfaceCreated twice, and my game starts twice. I have a static list of handlers for render and the handlers gets added twice, causing the render to be twice every frame. Thanks to you, I also found a bug in my framework here that I fixed just now. \$\endgroup\$ Jul 19, 2016 at 13:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .