Android and OpenGL give a black frame at startup

I am currently writing an Android app for my clients who have GLSurfaceView with GLSurfaceView.Renderer.

All my OpenGL stuff works just fine (this is basically a port of what another developer wrote on iOS in the first place). Except one. When the image loads and thus the OpenGL stuff loads, my background quickly flashes black, and then OpenGL starts rendering correctly (with my background). So what I do:

In onSurfaceCreated, I start with this:

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glClearColor(0.9f + 0.1f * (21.0f / 255),
            0.9f + 0.1f * (36.0f / 255),
            0.9f + 0.1f * (31.0f / 255), 1.0f);

    // Here goes my other stuff, if I comment all my other stuff out I still get the flash at startup
}

In my onDrawFrame method, I do this:

@Override
public void onDrawFrame(GL10 gl) {

    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    // My stuff, again, if I comment all this stuff out I still get the flash...
}

, , glClearColor (..) onSurfaceCreated, . glClearColor (..) (, , OpenGL ), .

, , , , ...

, ?

+4
1

, GLSurfaceView. XML:

<view class="android.opengl.GLSurfaceView"
    android:id="@+id/glview"
    android:background="@drawable/window_bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

window_bg , , .

, , onDrawFrame(), , :

boolean initialRenderHack;

//
// GLSurfaceView.Renderer
//
@Override
public void onDrawFrame(GL10 gl10) {

       // ... drawing code goes here ...

       // Remove the initial background
       if (!initialRenderHack) {
       initialRenderHack = true;
       view.post(new Runnable() {
           @Override
           public void run() {
               view.setBackgroundResource(0);
           }                
       });
    }

, " " , , onDrawFrame(), , runnable.

Android 4.4 . .

+3

All Articles