Awesome! Got it up and running here. You are my Android dev hero for the month if not longer! Where I can I paypal you $50; I'd send more if I could right now.. You also got a life long purchaser of all your games on the market. Folks... Support Mario and buy his games! I like your Newton game by the way! :)
I knew this was a trivial, but perhaps tedious exercise, so thanks for stepping up _and_ sharing your work / effort. I'm also rabble rousing now on the LWJGL community forums to get an ES version of LWJGL ported to Android. That would be absolutely fantastic as Slick2D plus many other LWJGL games could make it to Android sooner rather than later with few changes from their desktop counterparts. I'm not sure what license you may want to attribute to your work, but perhaps MIT or a completely open license that doesn't conflict with anything. If you need any further assistance I have a bunch of Android devices I can test on, but things work fine on the Droid / N1! Again you rock!!! This is fantastic.. The following is a slightly modified test that has a variable time kill fragment shader: --------------------------------------------- package com.badlogic.gdx; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLDisplay; import javax.microedition.khronos.opengles.GL10; import android.view.Menu; import android.view.MenuItem; import com.badlogic.gdx.backends.android.AndroidGL20; import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView; import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20; import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView.Renderer; import com.badlogic.gdx.graphics.GL20; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.Log; public class GL2Test extends Activity { GLSurfaceView view; int appCutoff1, appCutoff2; long startTime; int equationIndex = 0; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (checkGL20Support(this)) view = new GLSurfaceView20(this); else view = new GLSurfaceView(this); view.setRenderer(new TestRenderer()); setContentView(view); } public boolean onCreateOptionsMenu(Menu menu) { Menu menuEquations = menu.addSubMenu(10, 10, 0, "Kill Frag Equations (t == time)"); menuEquations.add(10, 0, 0, "x: .5 y: cos(t)"); menuEquations.add(10, 1, 1, "x: sin(t) y: .2"); menuEquations.add(10, 2, 2, "x: sin(t) y: cos(t)"); menuEquations.add(10, 3, 3, "x: sin(t)/2 y: cos(t)/2"); menuEquations.add(10, 4, 4, "x: .5*sin(3*t+4) y: .5*sin(t)"); menuEquations.add(10, 5, 5, "all killed; x&y: -1"); menuEquations.add(10, 6, 6, "none killed; x&y: 1"); return true; } public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() <= 6) equationIndex = item.getItemId(); return true; } protected void onPause() { super.onPause(); view.onPause(); } protected void onResume() { super.onResume(); view.onResume(); } private boolean checkGL20Support(Context context) { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(display, version); int EGL_OPENGL_ES2_BIT = 4; int[] configAttribs = { EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[10]; int[] num_config = new int[1]; egl.eglChooseConfig(display, configAttribs, configs, 10, num_config); egl.eglTerminate(display); return num_config[0] > 0; } class TestRenderer implements Renderer { AndroidGL20 gl2 = new AndroidGL20(); FloatBuffer vertices; int program; int viewportWidth, viewportHeight; private float calculate(int cutoff, int equation, float time) { switch (equation) { default: case 0: return cutoff == 0 ? 0.5f : (float) Math.cos(time); case 1: return cutoff == 0 ? (float) Math.sin(time) : 0.2f; case 2: return cutoff == 0 ? (float) Math.sin(time) : (float) Math.cos(time); case 3: return cutoff == 0 ? (float) Math.sin(time) / 2f : (float) Math.cos(time) / 2f; case 4: return cutoff == 0 ? (float) (0.5 * Math.sin(3 * time + 4)) : (float) (0.5 * Math.sin(time)); case 5: return cutoff == 0 ? -1f : -1f; // really just needs to be 0, but just a bit shows through... case 6: return cutoff == 0 ? 1f : 1f; } } public void onDrawFrame(GL10 gl) { gl2.glClearColor(0.7f, 0.7f, 0.7f, 1); gl2.glClear(GL20.GL_COLOR_BUFFER_BIT); gl2.glViewport(0, 0, viewportWidth, viewportHeight); gl2.glUseProgram(program); float currentTime = (System.currentTimeMillis() - startTime) / 1000f; gl2.glUniform1f(appCutoff1, calculate(0, equationIndex, currentTime)); gl2.glUniform1f(appCutoff2, calculate(1, equationIndex, currentTime)); gl2.glVertexAttribPointer(0, 3, GL20.GL_FLOAT, false, 0, vertices); gl2.glEnableVertexAttribArray(0); gl2.glDrawArrays(GL20.GL_TRIANGLES, 0, 3); } public void onSurfaceChanged(GL10 gl, int width, int height) { viewportWidth = width; viewportHeight = height; } public void onSurfaceCreated(GL10 gl, EGLConfig config) { startTime = System.currentTimeMillis(); String vertexShaderSrc = "attribute vec4 vPosition; \n" + "varying vec3 Position; \n" + "void main() \n" + "{ \n" + " Position = vec3(vPosition); \n" + " gl_Position = vPosition; \n" + "} \n"; String fragmentShaderSrc = "precision mediump float; \n" + "varying vec3 Position; \n" + "uniform float appCutoff1; \n" + "uniform float appCutoff2; \n" + "void main() \n" + "{ \n" + " vec3 ct; \n" + " float ss, tt; \n" + " vec3 pos = Position; \n" + " ss = pos.x * 7.1; \n" + " tt = pos.y * 7.1; \n" + " ss = fract (ss); \n" + " tt = fract (tt); \n" + " if ((ss > appCutoff1) && (tt > appCutoff2)) discard; \n" + " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 ); \n" + "} \n"; int vertexShader = loadShader(GL20.GL_VERTEX_SHADER, vertexShaderSrc); int fragmentShader = loadShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderSrc); program = gl2.glCreateProgram(); if (program == 0) throw new RuntimeException("creating program didn't work"); gl2.glAttachShader(program, vertexShader); gl2.glAttachShader(program, fragmentShader); gl2.glBindAttribLocation(program, 0, "vPosition"); gl2.glLinkProgram(program); ByteBuffer tmp = ByteBuffer.allocateDirect(4); tmp.order(ByteOrder.nativeOrder()); IntBuffer intbuf = tmp.asIntBuffer(); gl2.glGetProgramiv(program, GL20.GL_LINK_STATUS, intbuf); int linked = intbuf.get(0); if (linked == 0) { gl2.glGetProgramiv(program, GL20.GL_INFO_LOG_LENGTH, intbuf); int infoLogLength = intbuf.get(0); if (infoLogLength > 1) { Log.d("GL2", "couldn't link program: " + gl2.glGetProgramInfoLog(program)); } throw new RuntimeException("Creating program didn't work"); } appCutoff1 = gl2.glGetUniformLocation(program, "appCutoff1"); appCutoff2 = gl2.glGetUniformLocation(program, "appCutoff2"); float vVertices[] = {0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f}; tmp = ByteBuffer.allocateDirect(3 * 3 * 4); tmp.order(ByteOrder.nativeOrder()); vertices = tmp.asFloatBuffer(); vertices.put(vVertices); vertices.position(0); } private int loadShader(int type, String source) { ByteBuffer tmp = ByteBuffer.allocateDirect(4); tmp.order(ByteOrder.nativeOrder()); IntBuffer intbuf = tmp.asIntBuffer(); int shader = gl2.glCreateShader(type); if (shader == 0) throw new RuntimeException("creating the shader didn't work"); gl2.glShaderSource(shader, source); gl2.glCompileShader(shader); gl2.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf); int compiled = intbuf.get(0); if (compiled == 0) { gl2.glGetShaderiv(shader, GL20.GL_INFO_LOG_LENGTH, intbuf); int infoLogLength = intbuf.get(0); if (infoLogLength > 1) { String infoLog = gl2.glGetShaderInfoLog(shader); Log.d("GL2", "shader info: " + infoLog); } throw new RuntimeException("creating the shader didn't work"); } return shader; } } } On Mar 13, 2:29 am, Mario Zechner <badlogicga...@gmail.com> wrote: > Hey Michael, > http://groups.google.com/group/android-developers/browse_thread/threa... > hope that helps :) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en