Updating Shaders

We’ll also need to update our color shader. We defined our puck and mallet with a per-vertex position but not with a per-vertex color. Instead we’ll have to pass in the color as a uniform. The first thing we’ll do to make these changes is add a new constant to ShaderProgram:

AirHockeyWithImprovedMallets/src/com/airhockey/android/programs/ShaderProgram.java
 
protected​ ​static​ ​final​ ​String​ U_COLOR = ​"u_Color"​;

The next step is to update ColorShaderProgram. Go ahead and remove all references to aColorLocation, including getColorAttributeLocation, and then add the following uniform location definition:

AirHockeyWithImprovedMallets/src/com/airhockey/android/programs/ColorShaderProgram.java
 
private​ ​final​ ​int​ uColorLocation; ...

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.