1. 程式人生 > >GLSurfaceView使用-入門之HelloWorld--畫背景圖

GLSurfaceView使用-入門之HelloWorld--畫背景圖

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               
package com.example.opengl_01;import java.nio.ByteBuffer;import java.nio.ByteOrder;import java.nio.FloatBuffer;import
javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.opengles.GL10;import android.app.Activity;import android.opengl.GLSurfaceView;import android.os.Bundle;import android.util.Log;public class MainActivity extends Activity private final String TAG = "MainActivity"private
GLSurfaceView glSurefaceView; @Override public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_main);  glSurefaceView = new GLSurfaceView(this);  glSurefaceView.setRenderer(new GLSurfaceViewRender());  this
.setContentView(glSurefaceView); } @Override protected void onResume() {  super.onResume();  glSurefaceView.onResume(); } @Override protected void onPause() {  super.onStop();  glSurefaceView.onPause(); } class GLSurfaceViewRender implements GLSurfaceView.Renderer {  @Override  public void onSurfaceCreated(GL10 gl, EGLConfig config) {   Log.i(TAG, "onSurfaceCreated");   // 設定背景顏色   gl.glClearColor(0.0f, 0f, 1f, 0.5f);  }  @Override  public void onSurfaceChanged(GL10 gl, int width, int height) {   // 設定輸出螢幕大小   gl.glViewport(0, 0, width, height);   Log.i(TAG, "onSurfaceChanged");  }  @Override  public void onDrawFrame(GL10 gl) {   Log.i(TAG, "onDrawFrame");   // 清除螢幕和深度快取(如果不呼叫該程式碼, 將不顯示glClearColor設定的顏色)   // 同樣如果將該程式碼放到 onSurfaceCreated 中螢幕會一直閃動   gl.glClear(GL10.GL_COLOR_BUFFER_BIT);  } }}


           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述