Java tutorial
//package com.java2s; import android.util.Log; 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.glGetProgramInfoLog; import static android.opengl.GLES20.glGetProgramiv; import static android.opengl.GLES20.glLinkProgram; public class Main { private static final String TAG = "ShaderHelper"; private static final boolean IS_LOGGING_ON = true; /** * Links a vertex shader and a fragment shader together into an OpenGL * program. Returns the OpenGL program object ID, or 0 if linking failed. */ public static int linkProgram(int vertexShaderId, int fragmentShaderId) { // Create a new program object. final int programObjectId = glCreateProgram(); if (programObjectId == 0) { if (IS_LOGGING_ON) { Log.w(TAG, "Could not create new program"); } return 0; } // Attach the vertex shader to the program. glAttachShader(programObjectId, vertexShaderId); // Attach the fragment shader to the program. glAttachShader(programObjectId, fragmentShaderId); // Link the two shaders together into a program. glLinkProgram(programObjectId); // Get the link status. final int[] linkStatus = new int[1]; glGetProgramiv(programObjectId, GL_LINK_STATUS, linkStatus, 0); if (IS_LOGGING_ON) { // Print the program info log to the Android log output. Log.v(TAG, "Results of linking program:\n" + glGetProgramInfoLog(programObjectId)); } // Verify the link status. if (linkStatus[0] == 0) { // If it failed, delete the program object. glDeleteProgram(programObjectId); if (IS_LOGGING_ON) { Log.w(TAG, "Linking of program failed."); } return 0; } // Return the program object ID. return programObjectId; } }