1.實現GLSurfaceView.Renderer接口:
static class SimpleRender implements GLSurfaceView.Renderer{
Random random = new Random();
@Override
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
//設置材質和紋理
}
@Override
public void onSurfaceChanged(GL10 gl10, int i, int i1) {
//每當界面大小需要調整時就會調用,輸入參數包括新界面的寬和高,以像素爲單位
}
@Override
public void onDrawFrame(GL10 gl10) {//隨機顏色清屏
gl10.glClearColor(random.nextFloat(), random.nextFloat(), random.nextFloat(), 1);
gl10.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
}
2.調用
GLSurfaceView glSurfaceView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
glSurfaceView = new GLSurfaceView(this);
glSurfaceView.setRenderer(new SimpleRender());
setContentView(glSurfaceView);
}
@Override
protected void onResume() {
super.onResume();
glSurfaceView.onResume();
}
@Override
protected void onPause() {
super.onPause();
glSurfaceView.onPause();
}
Android GLSurfaceView學習(1):屏幕清理程序,使用隨機顏色刷屏
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.