Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.opengl.GLES20;

public class Main {
    public static int createShader(int type, String source) {
        String typeString;
        if (type == GLES20.GL_VERTEX_SHADER)
            typeString = "vertex";
        else if (type == GLES20.GL_FRAGMENT_SHADER)
            typeString = "fragment";
        else
            throw new RuntimeException("Unknown shader type");

        int sh = GLES20.glCreateShader(type);
        if (sh <= 0) {
            throw new RuntimeException("Could not create " + typeString + " shader");
        }
        GLES20.glShaderSource(sh, source);
        GLES20.glCompileShader(sh);
        int[] status = new int[1];
        GLES20.glGetShaderiv(sh, GLES20.GL_COMPILE_STATUS, status, 0);
        if (status[0] <= 0) {
            String message = GLES20.glGetShaderInfoLog(sh);
            GLES20.glDeleteShader(sh);
            throw new RuntimeException("Could not compile " + typeString + " shader: " + message);
        }

        return sh;
    }
}