Game Development Reference
In-Depth Information
@Override
protected void onResume() {
super.onResume();
mGLSurfaceView.onResume();
}
}
When the application loses focus or resumes, the onPause() or onResume() method will be
called, respectively. These methods delegate to the surface view ( GLSurfaceView ) to take
the appropriate action, such as saving application state or suspending/resuming the
rendering process.
Surface View
The class GLSurfaceView (see Listing 3-6) defines the surface where the tumbling cubes
animation will take place. The class constructor starts by initializing a callback to receive
notifications when the surface is changed, created, or destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
By implementing SurfaceHolder.Callback and calling SurfaceHolder.addCallback() , the
class will receive the events:
surfaceCreated(SurfaceHolder holder) : This is called immediately after
the surface is first created. In this case, the surface delegates to the
inner thread GLThread.surfaceCreated() .
surfaceDestroyed(SurfaceHolder holder) : This method is called
immediately before a surface is being destroyed. After returning from
this call, the surface should not be accessed. In this case, the method
delegates to the rendering thread GLThread.surfaceDestroyed() .
surfaceChanged(SurfaceHolder holder, int format, int w, int h) : This
method is called immediately after any structural changes (format or size)
have been made to the surface. Here is where you tell the inner thread that
the size has changed. This method is always called at least once, after
surfaceCreated() . The second argument of this method ( format ) is the
pixel format of the graphics defined in the PixelFormat class.
Listing 3-6. Surface View for the GL Cubes Sample
package opengl.scenes;
import opengl.jni.Natives;
import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
 
Search WWH ::




Custom Search