From 7f49e9fd243d445c7e48bbbac6c1c5912bc2e550 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 1 Nov 2012 21:09:48 -0400 Subject: [PATCH] extend GLSurfaceView and Renderer --- AndroidManifest.xml | 1 + .../holtrop/opengltest/MainOpenGL.java | 7 +++++- .../holtrop/opengltest/MyGLSurfaceView.java | 16 +++++++++++++ .../holtrop/opengltest/MyRenderer.java | 24 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/com/homelinux/holtrop/opengltest/MyGLSurfaceView.java create mode 100644 src/com/homelinux/holtrop/opengltest/MyRenderer.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f917340..7d47058 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -12,4 +12,5 @@ + diff --git a/src/com/homelinux/holtrop/opengltest/MainOpenGL.java b/src/com/homelinux/holtrop/opengltest/MainOpenGL.java index 9e23a16..81fda1e 100644 --- a/src/com/homelinux/holtrop/opengltest/MainOpenGL.java +++ b/src/com/homelinux/holtrop/opengltest/MainOpenGL.java @@ -1,15 +1,20 @@ package com.homelinux.holtrop.opengltest; +import android.opengl.GLSurfaceView; import android.app.Activity; import android.os.Bundle; public class MainOpenGL 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 MyGLSurfaceView(this); + setContentView(mGLView); } } diff --git a/src/com/homelinux/holtrop/opengltest/MyGLSurfaceView.java b/src/com/homelinux/holtrop/opengltest/MyGLSurfaceView.java new file mode 100644 index 0000000..96ab19b --- /dev/null +++ b/src/com/homelinux/holtrop/opengltest/MyGLSurfaceView.java @@ -0,0 +1,16 @@ +package com.homelinux.holtrop.opengltest; + +import android.opengl.GLSurfaceView; +import android.content.Context; + +public class MyGLSurfaceView extends GLSurfaceView +{ + public MyGLSurfaceView(Context context) + { + super(context); + + setRenderer(new MyRenderer()); + + setEGLContextClientVersion(2); + } +} diff --git a/src/com/homelinux/holtrop/opengltest/MyRenderer.java b/src/com/homelinux/holtrop/opengltest/MyRenderer.java new file mode 100644 index 0000000..4a046da --- /dev/null +++ b/src/com/homelinux/holtrop/opengltest/MyRenderer.java @@ -0,0 +1,24 @@ +package com.homelinux.holtrop.opengltest; + +import android.opengl.GLSurfaceView; +import android.opengl.GLES20; +import javax.microedition.khronos.opengles.GL10; +import javax.microedition.khronos.egl.EGLConfig; + +public class MyRenderer implements GLSurfaceView.Renderer +{ + public void onSurfaceCreated(GL10 unused, EGLConfig config) + { + GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); + } + + public void onDrawFrame(GL10 unused) + { + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + } + + public void onSurfaceChanged(GL10 unused, int width, int height) + { + GLES20.glViewport(0, 0, width, height); + } +}