J.M.Sanchez
J.M.Sanchez

Reputation: 55

OpenGL ES buffers not clean

I am currently working on a 2D game rendered in OpenGL ES in Android. My sprites seem to render correctly but, sadly, they keep on screen when I do not want them renderer. When I draw a frame with nothing in buffers I can still see previously drawn sprites.

This is the code.

public void renderFrame()
{
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glViewport(0, 0, viewPort.getWidth(), viewPort.getHeight());
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(position.x - frustumWidth * zoom / 2, 
                position.x + frustumWidth * zoom/ 2, 
                position.y - frustumHeight * zoom / 2, 
                position.y + frustumHeight * zoom/ 2, 
                1, -1);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

    /*
     *   Buffer filling code goes here
     */

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    verticesIntBuffer.position(0);
    gl.glVertexPointer(2, GL10.GL_FLOAT, vertexSize, vertices);

    gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_SHORT,                     
                   shortBufferIndices);

    gl.glDisable(GL10.GL_BLEND);
}

I presumed glClear would clean buffers but this doesn't look like it in here.

This solution did not work for me either Clearing/releasing OpenGL ES buffers

Any ideas on how to explicity clean buffers? Another ideas of what could be happening due to rendering previous sprites still occurring?

Thanks a lot for your patience.

Upvotes: 0

Views: 422

Answers (1)

keaukraine
keaukraine

Reputation: 5364

You should clear both color and depth buffer:

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

Upvotes: 1

Related Questions