Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:00+00:00 2026-06-18T01:10:00+00:00

I ran into different behaviors with the GLSurfaceView. AFAIK it is the responsibility of

  • 0

I ran into different behaviors with the GLSurfaceView.
AFAIK it is the responsibility of the program to clear the buffer (color and depth ) each frame. Which means that if I don’t clear the buffer I get the content of the last frame ( or the one before that for double buffering ).

It seems though as if the buffer is cleared no matter what on some devices. I ran the following modification of the “Hello Triangle” program from the Addison Wesley OpenglES2.0 Programming Guide on some test devices with different results:

  • Acer Iconia A500 (4.0.3): not cleared (expected behavior)
  • Sony XPERIA Go (4.0.4): cleared
  • Galaxy S3 (4.1.1): cleared
  • LG Optimus 4x HD (4.0.3): not cleared
  • Samsung Galaxy Tab 20.1 (4.0.4): not cleared
  • Motorola Xoom ( 3.2): not cleared
  • Galaxy S2 (4.1.2 – rooted): cleared

Is there a way to force getting an unchanged buffer with each draw callback?

The result for the devices with cleared screen looks like this:
cleared screen
uncleared screen - expected behavior

The test activity looks like this:

package com.example.glcleartest;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;

public class MainActivity extends Activity {

protected static final int NUM_VERTICES = 3;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    GLSurfaceView glview = (GLSurfaceView) findViewById(R.id.glview);
    glview.setEGLConfigChooser(false);
    glview.setEGLContextClientVersion(2);
    glview.setRenderer(new Renderer() {

        private int programObject;
        private FloatBuffer vertexBuffer;

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
            GLES20.glViewport(0, 0, width, height);
            init();
        }

        @Override
        public void onDrawFrame(GL10 gl) {
            float x = 0.1f*(float) Math.sin(System.currentTimeMillis()/1000.0);
            float[] vVertices = new float[]{x, 0.5f, 0.0f,
                    x-0.5f, -0.5f, 0.0f,
                    x+0.5f, -0.5f, 0.0f};
            vertexBuffer.rewind();
            vertexBuffer.put(vVertices);
            vertexBuffer.rewind();


            // Use the program object
            GLES20.glUseProgram(programObject);
            int handle = GLES20.glGetUniformLocation(programObject, "uColor");
            float r = (float) (0.5f+Math.sin(System.currentTimeMillis()/1000.0));
            float g = (float) (0.5f+Math.sin(System.currentTimeMillis()/300.0));
            GLES20.glUniform4f(handle, r, g,0,1);

            // Load the vertex data
            GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
            GLES20.glEnableVertexAttribArray(0);
            GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);             
        }

        private void error(String s) {
            Log.e("GLTEST", s);
        }

        private int loadShader(int shaderType, String source) {
            if (shaderType != GLES20.GL_FRAGMENT_SHADER && shaderType != GLES20.GL_VERTEX_SHADER) {
                throw new RuntimeException("Illegal shader type");
            }

            int shader = GLES20.glCreateShader(shaderType);
            if (shader != 0) {
                GLES20.glShaderSource(shader, source);
                GLES20.glCompileShader(shader);
                int[] compiled = new int[1];
                GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
                if (compiled[0] == 0) {
                    error("Could not compile shader :");
                    error(GLES20.glGetShaderInfoLog(shader));
                    GLES20.glDeleteShader(shader);
                    shader = 0;
                    throw new RuntimeException("Shader Syntax / compilation error");
                }
            }
            return shader;
        }

        private void init() {
            String vShaderStr = "attribute vec4 vPosition; \n" + 
                                    "void main() \n" + "{ \n" + 
                                    " gl_Position = vPosition; \n" + 
                                    "} \n";
            String fShaderStr = "precision mediump float; \n" +
                                        "uniform vec4 uColor;" +
                                        "void main() \n" + 
                                        "{ \n" + 
                                        " gl_FragColor = uColor; \n" + 
                                        "} \n";

            ByteBuffer vbb = ByteBuffer.allocateDirect(NUM_VERTICES*3*4);
            vbb.order(ByteOrder.nativeOrder());
            vertexBuffer = vbb.asFloatBuffer();

            int vertexShader;
            int fragmentShader;

            // Load the vertex/fragment shaders
            vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vShaderStr);
            fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fShaderStr);

            // Create the program object
            programObject = GLES20.glCreateProgram();
            if (programObject == 0)
                return;

            GLES20.glAttachShader(programObject, vertexShader);
            GLES20.glAttachShader(programObject, fragmentShader);
            // Bind vPosition to attribute 0
            GLES20.glBindAttribLocation(programObject, 0, "vPosition");
            // Link the program
            GLES20.glLinkProgram(programObject);
            int[] linkStatus = new int[1];
            GLES20.glGetProgramiv(programObject, GLES20.GL_LINK_STATUS, linkStatus, 0);

            if (linkStatus[0] != GLES20.GL_TRUE) {
                error("Could not link program: ");
                error(GLES20.glGetProgramInfoLog(programObject));
                GLES20.glDeleteProgram(programObject);
                programObject = 0;
            }
        }
    });
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:10:02+00:00Added an answer on June 18, 2026 at 1:10 am

    If you want to keep your backbuffer contents after swapping, you have to set the EGL_SWAP_BEHAVIOR attribute of your swap surface to EGL_BUFFER_PRESERVED, as documented by the EGL API. Do realize though that on most platforms, this will be a fairly large performance hit. You’re much better off just redrawing the frame in most cases.

    For a bit of history: see http://www.khronos.org/registry/egl/specs/EGLTechNote0001.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran into something weird. I have two JSON arrays which holds different
I ran into this issue while testing a rails app deployed to two different
I just ran into a SQL query with about 5 different columns in the
I ran into a scenario where I had a delegate callback which could occur
I ran into an issue with my Nodejs application. I have two different apps
Working with C:\Program Files (x86) I ran into a strange issue with a program
Ok, I ran into this tree question which LOOKED simple, but started driving me
I just ran into some code that overuse semicolons, or use semicolon for different
I ran into ss64.com which provides good help regarding how to write batch scripts
I ran into an issue, where I got the same hash value for different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.