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; //from w ww .j a v a 2 s . co m import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLES20; //filename: SimpleTriangleRenderer.java public class ES20SimpleTriangleRenderer extends ES20AbstractRenderer { //A raw native buffer to hold the point coordinates private FloatBuffer mFVertexBuffer; private static final int FLOAT_SIZE_BYTES = 4; private final float[] mTriangleVerticesData = { // X, Y, Z -1.0f, -0.5f, 0, 1.0f, -0.5f, 0, 0.0f, 1.11803399f, 0 }; public ES20SimpleTriangleRenderer() { ByteBuffer vbb = ByteBuffer.allocateDirect(mTriangleVerticesData.length * FLOAT_SIZE_BYTES); vbb.order(ByteOrder.nativeOrder()); mFVertexBuffer = vbb.asFloatBuffer(); mFVertexBuffer.put(mTriangleVerticesData); mFVertexBuffer.position(0); } protected void draw(GL10 gl, int positionHandle) { GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, mFVertexBuffer); checkGlError("glVertexAttribPointer maPosition"); //mFVertexBuffer.position(TRIANGLE_VERTICES_DATA_UV_OFFSET); GLES20.glEnableVertexAttribArray(positionHandle); checkGlError("glEnableVertexAttribArray maPositionHandle"); this.setupMatrices(); GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3); checkGlError("glDrawArrays"); } }