Android Open Source - ExpertAndroid E S20 Simple Triangle Renderer

From Project

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.

Java Source Code

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;

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);
        mFVertexBuffer = vbb.asFloatBuffer();

    protected void draw(GL10 gl, int positionHandle)
        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false,
                0, mFVertexBuffer);
        checkGlError("glVertexAttribPointer maPosition");
        checkGlError("glEnableVertexAttribArray maPositionHandle");

        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

Java Source Code List