Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import static android.opengl.GLES20.GL_LINK_STATUS;

import static android.opengl.GLES20.glAttachShader;

import static android.opengl.GLES20.glCreateProgram;

import static android.opengl.GLES20.glDeleteProgram;

import static android.opengl.GLES20.glGetProgramiv;

import static android.opengl.GLES20.glLinkProgram;

import android.util.Log;

public class Main {
    private static final String TAG = "ShaderHelper";

    public static int linkProgram(int vertexId, int fragmentId) {
        int programObjectId = glCreateProgram();

        if (programObjectId != 0) {
            //creation succesfull
            glAttachShader(programObjectId, vertexId);
            glAttachShader(programObjectId, fragmentId);

            //link
            glLinkProgram(programObjectId);

            //retrieve status
            final int[] status = new int[1];
            glGetProgramiv(programObjectId, GL_LINK_STATUS, status, 0);

            if (status[0] != 0) {

                return programObjectId;
            } else {
                //linking failed
                glDeleteProgram(programObjectId);
                Log.w(TAG, "linking failed");

                return 0;
            }
        } else {
            Log.w(TAG, "couldn't create program");
            return 0;
        }
    }
}