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

Rendering with the New Color Attribute

Now that we’ve added a color attribute to our data and we’ve updated the vertex and fragment shaders to use this attribute, the next steps are to remove the old code that passed in the color via a uniform and to tell OpenGL to read in colors as a vertex attribute.

Updating Constants

Let’s add the following constants to the top of AirHockeyRenderer:

AirHockey2/src/com/airhockey/android/AirHockeyRenderer.java
 
private​ ​static​ ​final​ ​String​ A_COLOR = ​"a_Color"​;
 
private​ ​static​ ​final​ ​int​ COLOR_COMPONENT_COUNT = 3;
 
private​ ​static​ ​final​ ​int​ STRIDE =
 
(POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * BYTES_PER_FLOAT;

We’ll also need a new member variable:

AirHockey2/src/com/airhockey/android/AirHockeyRenderer.java ...

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