extend GLSurfaceView and Renderer

This commit is contained in:
Josh Holtrop 2012-11-01 21:09:48 -04:00
parent 70c1b327a1
commit 7f49e9fd24
4 changed files with 47 additions and 1 deletions

View File

@ -12,4 +12,5 @@
</intent-filter>
</activity>
</application>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
</manifest>

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}