开发者

GLSurfaceView onPause shows only a black screen

I am developing an little OpenGL Activity, it's composed by this layout:

<RelativeLayout  
                android:id="@+id/vt_layout_opengl"
                android:orientation="horizontal" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:visibility="gone"


        >

            <android.opengl.GLSurfaceView
                    android:id="@+id/surface_vt"
                    android:layout_width="900dp" 
                    android:layout_height="285dp"

            />   

            <RelativeLayout
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    android:layout_below="@id/surface_vt"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/barra_menu_vt"

                  >

                    <ImageButton android:id="@+id/vt_left_arrow" 
                                 android:layout_width="wrap_content" 
                                 android:layout_height="wrap_content"
                                 android:layout_alignParentLeft="true"
                                 android:layout_marginLeft="20dp"
                                 android:background="@drawable/prev_a"
                                 android:onClick="prec"

                    />
                    <ImageButton android:id="@+id/vt_right_arrow" 
                                 android:layout_width="wrap_content" 
                                 android:layout_height="wrap_content"
                                 android:background="@drawable/next_a"
                                 android:layout_toRightOf="@+id/vt_left_arrow"
                                 android:layout_marginLeft="20dp"
                                 android:onClick="next"
                    />
                    <TextView
                        android:id="@+id/vt_description" 
                        android:layout_width="wrap_content" 
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@+id/vt_right_arrow"
                        android:layout_marginLeft="30dp"
                        android:maxLength="30"
                        android:singleLine="true"
                        an开发者_StackOverflow中文版droid:ellipsize="marquee"
                    />

                    <ImageButton android:id="@+id/vt_information" 
                                 android:layout_width="wrap_content" 
                                 android:layout_height="wrap_content"
                                 android:layout_toLeftOf="@+id/vt_addbookmarks"
                                 android:layout_marginRight="20dp"
                                 android:background="@drawable/info_a"
                                 android:onClick="info"

                    />
                    <ImageButton android:id="@+id/vt_addbookmarks" 
                                 android:layout_width="wrap_content" 
                                 android:layout_height="wrap_content"
                                 android:layout_toLeftOf="@+id/vt_preferences"
                                 android:layout_marginRight="20dp"
                                 android:background="@drawable/book_a"
                                 android:onClick="bookmark"
                    />
                    <ImageButton android:id="@+id/vt_preferences" 
                                 android:layout_width="wrap_content" 
                                 android:layout_height="wrap_content"
                                 android:layout_alignParentRight="true"
                                 android:layout_marginRight="20dp"
                                 android:background="@drawable/sett_a"
                                 android:onClick="settings"
                    />




                </RelativeLayout>


        </RelativeLayout>

It's shows an View like this:

GLSurfaceView onPause shows only a black screen

But when I press the home button and I return on my application I can see only a black screen, the GLSurfaceView and also the RelativeLayout are not displayed!!

After about two minuts system say:

GLSurfaceView onPause shows only a black screen

I am very frustrating, I call GLSurface onPause() and onResume() when my Activity calls the corresponding methods.

Someone can help me!!????

I post some of my code:

@Override
    public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG,"onCreate()");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.virtualtour);
        loading_ly = (RelativeLayout) findViewById(R.id.vt_layout_loading);
        panorama_description = (TextView) findViewById(R.id.vt_description);
        virtualtour_relatively = (RelativeLayout) findViewById(R.id.vt_layout_opengl);
        vt_handler = new VirtualTourHandler(this);
        ext_container = new GLExtensionContainer();
        th_checkGL = new ThreadCheckOpenGL(ext_container, extensions_requested,vt_handler);
       th_checkGL.start();
        mFacebook = new Facebook(ArounderTouchMainActivity.APP_ID);
        mAsyncRunner = new AsyncFacebookRunner(mFacebook);
        msg = vt_handler.obtainMessage();
        output_thread =  msg.getData();
        output_thread.putInt(VirtualTour.TYPE_TAG, VirtualTour.START_TAG);
        vt_handler.handleMessage(msg);
      }

This is my Handler inner class (I use it for switch texture when users performs some action)

@Override
        public void handleMessage(Message msg) {


            bd = msg.getData();
            type = bd.getInt(TYPE_TAG);
            bd = msg.getData();

            switch (type) {
                case GL_EXTENSIONS_CHECK_TAG:
                    showDialog(GL_EXTENSIONS_CHECK_DIALOG);
                    break;
                case START_TAG:
                    Log.d(TAG, "START_TAG");
                    loading_ly.setVisibility(View.VISIBLE);
                    virtualtour_relatively.setVisibility(View.GONE);
                    progress_bar.setProgress(0);
                    thread = new DownloadImageProgressBar(vt_handler,getActivity());
                    thread.execute(panorama_input.get(position).getUrl_virtual());
                    break;
                case BAR_TAG:
                    progress = bd.getInt(PROGRESS_TAG);
                    if(progress <= 100)
                        progress_bar.setProgress(progress);
                    break;

                case SHUTDOWN_TAG:
                    finish();
                    break;
                case SHOW_TAG:
                Log.d(TAG, "SHOW_TAG");
                if(first_visualization){
                    glSurface = (GLSurfaceView) findViewById(R.id.surface_vt);
                    glSurface.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
                    renderer = new OpenGLRenderer(first_data,second_data,sphere,vt_handler,ext_container, ( (panorama_input.get(position)).getType().compareTo(CardImage.SPHERE) == 0));
                    glSurface.setRenderer(renderer);
                    first_visualization = false;
                }
                // potrebbe essere fatto molto meglio: ricorda! 
                panorama_description.setText(panorama_input.get(position).getTitolo());
                loading_ly.setVisibility(View.GONE);
                virtualtour_relatively.setVisibility(View.VISIBLE);

                renderer.setImage(first_data, second_data,( (panorama_input.get(position)).getType().compareTo(CardImage.SPHERE) == 0));
                renderer.resetZoom();
                renderer.resetAngle();
                renderer.startTimer();  
                enable_touch = false;
                case NOCONNECTION_ERROR_TAG:
                    showDialog(OUTOFMEMORY_ERROR_DIALOG);
                    break;

                case OUTOFMEMORY_ERROR_TAG:
                    showDialog(OUTOFMEMORY_ERROR_DIALOG);
                    break;


                default:
                    break;
            }
            return;

        }


    }

The DownloadImageProgressBar is a AsyncTask which downloads images from the web and performs some UI actions through the Activity Handler.

There are my onPause and onResume methods:

 @Override
protected void onResume() {
    Log.d(TAG,"onResume()");
    super.onResume();
    if(glSurface != null)
        glSurface.onResume();
}

   @Override
protected void onPause() {
     Log.d(TAG,"onPause()");   
     super.onPause();
     glSurface.onPause();
}

I call this methods in onSurfaceChanged and onSurfaceCreated:

public void setGLTexture(GL10 gl10) {

        GL11 gl = (GL11) gl10;

        //Generate one texture pointer...
        gl.glGenTextures(2, textures_id);
        gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
        //...and bind it to our array
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_id.get(0));
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );
        gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, first, 0);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_id.get(1));
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );
        gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, second, 0);
        return;
    }

I have another question, when my activity switch in background the textures images I downloaded before are deleted?

It's possible that this is the issues?


When you press 'home', the GL context is lost.

From the Android documentation:

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The onSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this.

You can read about it here.

To fix the problem, perform all OpenGL texture and initialization in your renderer's onSurfaceChanged.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜