glview.java
来自「android 下学习openGL的一个不错demo」· Java 代码 · 共 67 行
JAVA
67 行
/*** * Excerpted from "Hello, Android!", * published by The Pragmatic Bookshelf. * Copyrights apply to this code. It may not be used to create training material, * courses, books, articles, and the like. Contact us if you are in doubt. * We make no guarantees that this code is fit for any purpose. * Visit http://www.pragmaticprogrammer.com/titles/eband for more book information.***/
package com.mot.opengl;
import android.content.Context;
import android.util.Log;import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
class GLView extends SurfaceView implements SurfaceHolder.Callback {
private final String TAG = "GLView";
private GLThread glThread; private int type;
GLView(Context context, int type) {
super(context); this.type = type;
// Install a SurfaceHolder.Callback so we get notified when
// the underlying surface is created and destroyed
getHolder().addCallback(this);
// Use hardware acceleration if available
getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created so start our drawing thread Log.e(TAG,"surfaceCreated");
glThread = new GLThread(this,type); glThread.setRunning(true);
glThread.start();
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.e(TAG,"surfaceDestroyed");
// Stop our drawing thread. The Surface will be destroyed
// when we return glThread.setRunning(false);
glThread.requestExitAndWait();
glThread = null;
}
public void surfaceChanged(SurfaceHolder holder, int format,
int w, int h) { Log.e(TAG,"surfaceChanged");
// TODO: handle window size changes
} public GLThread getThread() { return glThread; }
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?