androidでopenglesをつかってみる。画面の表示
まずは、アクティビティの設定。
import android.app.Activity; import android.os.Bundle; import android.opengl.GLSurfaceView; public class MainActivity extends Activity { private GLSurfaceView mGLView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); mGLView = new GLSurfaceView(this); mGLView.setRenderer(new GLRenderer()); this.setContentView(mGLView); } @Override protected void onPause(){ super.onPause(); mGLView.onPause(); } @Override protected void onResume(){ super.onResume(); mGLView.onResume(); } }
次にレンダラー。
import android.opengl.GLSurfaceView; import javax.microedition.khronos.egl.*; import javax.microedition.khronos.opengles.*; public class GLRenderer implements GLSurfaceView.Renderer{ // Renderer //------------------------------- @Override public void onDrawFrame(GL10 gl){ gl.glClearColor(1.0f, 1.0f, 0.0f, 1.0f);//背景色 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); } @Override public void onSurfaceChanged(GL10 gl, int width, int height){ gl.glViewport(0, 0, width, height); } @Override public void onSurfaceCreated(GL10 gl, EGLConfig config){ } }