Compiling Shaders

Now that we’ve read in the shader source from our files, the next step is to compile each shader. We’ll create a new helper class that is going to create a new OpenGL shader object, compile our shader code, and return the shader object for that shader code. Once we have this boilerplate code in place, we’ll be able to reuse it in our future projects.

To begin, create a new class, ShaderHelper, and add the following code inside the class:

AirHockey1/src/com/airhockey/android/util/ShaderHelper.java
 
private​ ​static​ ​final​ ​String​ TAG = ​"ShaderHelper"​;
 
 
public​ ​static​ ​int​ compileVertexShader(​String​ shaderCode) {
 
return​ compileShader(GL_VERTEX_SHADER, shaderCode);
 
}
 
 
public​ ​static​ ​int​ compileFragmentShader(​ ...

Get OpenGL ES 2 for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.