O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required