Back to project page ExpertAndroid.
The source code is released under:
MIT License
If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.iuriio.demos.expertandroid.ch9openglexperiments; //ww w. ja va2s . c om import android.content.Context; import android.os.SystemClock; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.ShortBuffer; import javax.microedition.khronos.opengles.GL10; /** * Created by iuriio on 10/26/13. */ public class AnimatedSimpleTriangleRenderer extends AbstractRenderer { private static final int VERTS = 3; private FloatBuffer vertexBuffer; private ShortBuffer indexBuffer; public AnimatedSimpleTriangleRenderer(Context context) { ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4); vbb.order(ByteOrder.nativeOrder()); this.vertexBuffer = vbb.asFloatBuffer(); ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2); ibb.order(ByteOrder.nativeOrder()); this.indexBuffer = ibb.asShortBuffer(); float[] coords = { -0.5f, -0.5f, 0, // (x1,y1,z1) 0.5f, -0.5f, 0, 0.0f, 0.5f, 0 }; for(int i = 0; i < VERTS; i++) { for (int j = 0; j < 3; j++) { this.vertexBuffer.put(coords[i * 3 + j]); } } final short[] indecesArray = { 0, 1, 2 }; for (int i = 0; i < 3; i++) { this.indexBuffer.put(indecesArray[i]); } this.vertexBuffer.position(0); this.indexBuffer.position(0); } @Override protected void draw(GL10 gl) { long time = SystemClock.uptimeMillis(); float angle = 0.090f * ((int) time); gl.glRotatef(angle, 0, 0, 1.0f); gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, this.vertexBuffer); gl.glDrawElements( GL10.GL_TRIANGLES, VERTS, GL10.GL_UNSIGNED_SHORT, this.indexBuffer); } }