Game Development Reference
In-Depth Information
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 5-3. 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;
/**
* An implementation of SurfaceView that uses the dedicated surface for
* displaying an OpenGL animation. This allows the animation to run in a
* separate thread, without requiring that it be driven by the update
* mechanism of the view hierarchy.
*
* The application-specific rendering code is delegated to a GLView.Renderer
* instance.
*/
public class GLSurfaceView extends SurfaceView
implements SurfaceHolder.Callback
{
public GLSurfaceView(Context context) {
super(context);
init();
}
public GLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed
Search WWH ::




Custom Search