// Path: app/src/main/java/com/demo/amazing/widget/MyRender.java
// public class MyRender implements GLSurfaceView.Renderer {
// 
//     private Triangle triangle;
// 
//     private Square square;
// 
//     private final float[] projectionMatrix = new float[16];
// 
//     private final float[] viewMatrix = new float[16];
// 
//     private final float[] mVPMatrix = new float[16];
// 
//     private final float[] RotationMatrix = new float[16];
// 
//     private volatile float angle;
// 
//     @Override
//     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//         GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
// 
//         triangle = new Triangle();
//         square = new Square();
//     }
// 
//     @Override
//     public void onSurfaceChanged(GL10 gl, int width, int height) {
//         GLES20.glViewport(0, 0, width, height);
// 
//         float ratio = (float) width / height;
// 
//         Matrix.frustumM(projectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
//     }
// 
//     @Override
//     public void onDrawFrame(GL10 gl) {
// 
//         float[] scratch = new float[16];
// 
//         GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// 
//         Matrix.setLookAtM(viewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// 
//         Matrix.multiplyMM(mVPMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
// 
// //        long time = SystemClock.uptimeMillis() % 4000L;
// //        float angle = 0.090f * ((int) time);
// //        Log.e("angle", "angle=" + angle);
//         Matrix.setRotateM(RotationMatrix, 0, angle, 0, 0, -1.0f);
// 
//         Matrix.multiplyMM(scratch, 0, mVPMatrix, 0, RotationMatrix, 0);
// 
//         triangle.draw(scratch);
//     }
// 
//     public static int loadShader(int type, String shaderCode) {
//         int shader = GLES20.glCreateShader(type);
// 
//         GLES20.glShaderSource(shader, shaderCode);
//         GLES20.glCompileShader(shader);
//         return shader;
//     }
// 
//     public float getAngle() {
//         return angle;
//     }
// 
//     public void setAngle(float angle) {
//         this.angle = angle;
//     }
// }


import android.opengl.GLES20;
import com.demo.amazing.widget.MyRender;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

    private final int program;

    private int positionHandle;

    private int colorHandle;

    private int mVPHandle;

    private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;

    private final int vertexStride = COORDS_PER_VERTEX * 4;

    // Set color with red, green, blue and alpha (opacity) values
    float color[] = {0.63671875f, 0.76953125f, 0.22265625f, 1.0f};
    //float color[] = {0.0f, 1.0f, 0.0f, 1.0f};
    public Triangle() {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(triangleCoords.length * 4);

        byteBuffer.order(ByteOrder.nativeOrder());

        vertexBuffer = byteBuffer.asFloatBuffer();

        vertexBuffer.put(triangleCoords);
        vertexBuffer.position(0);

        int vertexShader = MyRender.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);

        int fragmentShader = MyRender.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

// Path: app/src/main/java/com/demo/amazing/widget/MyRender.java
// public class MyRender implements GLSurfaceView.Renderer {
// 
//     private Triangle triangle;
// 
//     private Square square;
// 
//     private final float[] projectionMatrix = new float[16];
// 
//     private final float[] viewMatrix = new float[16];
// 
//     private final float[] mVPMatrix = new float[16];
// 
//     private final float[] RotationMatrix = new float[16];
// 
//     private volatile float angle;
// 
//     @Override
//     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//         GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
// 
//         triangle = new Triangle();
//         square = new Square();
//     }
// 
//     @Override
//     public void onSurfaceChanged(GL10 gl, int width, int height) {
//         GLES20.glViewport(0, 0, width, height);
// 
//         float ratio = (float) width / height;
// 
//         Matrix.frustumM(projectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
//     }
// 
//     @Override
//     public void onDrawFrame(GL10 gl) {
// 
//         float[] scratch = new float[16];
// 
//         GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// 
//         Matrix.setLookAtM(viewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
// 
//         Matrix.multiplyMM(mVPMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
// 
// //        long time = SystemClock.uptimeMillis() % 4000L;
// //        float angle = 0.090f * ((int) time);
// //        Log.e("angle", "angle=" + angle);
//         Matrix.setRotateM(RotationMatrix, 0, angle, 0, 0, -1.0f);
// 
//         Matrix.multiplyMM(scratch, 0, mVPMatrix, 0, RotationMatrix, 0);
// 
//         triangle.draw(scratch);
//     }
// 
//     public static int loadShader(int type, String shaderCode) {
//         int shader = GLES20.glCreateShader(type);
// 
//         GLES20.glShaderSource(shader, shaderCode);
//         GLES20.glCompileShader(shader);
//         return shader;
//     }
// 
//     public float getAngle() {
//         return angle;
//     }
// 
//     public void setAngle(float angle) {
//         this.angle = angle;
//     }
// }


// Path: app/src/main/java/com/demo/amazing/bean/Triangle.java
import android.opengl.GLES20;
import com.demo.amazing.widget.MyRender;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;


    private final int program;

    private int positionHandle;

    private int colorHandle;

    private int mVPHandle;

    private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;

    private final int vertexStride = COORDS_PER_VERTEX * 4;

    // Set color with red, green, blue and alpha (opacity) values
    float color[] = {0.63671875f, 0.76953125f, 0.22265625f, 1.0f};
    //float color[] = {0.0f, 1.0f, 0.0f, 1.0f};
    public Triangle() {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(triangleCoords.length * 4);

        byteBuffer.order(ByteOrder.nativeOrder());

        vertexBuffer = byteBuffer.asFloatBuffer();

        vertexBuffer.put(triangleCoords);
        vertexBuffer.position(0);

        int vertexShader = MyRender.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);

        int fragmentShader = MyRender.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

        program = GLES20.glCreateProgram();