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

Adding an Object Builder

Now we can start writing our object builder class. Let’s create a class in the package com.airhockey.android.objects called ObjectBuilder. Start out with the following code inside the class:

AirHockeyWithImprovedMallets/src/com/airhockey/android/objects/ObjectBuilder.java
 
private​ ​static​ ​final​ ​int​ FLOATS_PER_VERTEX = 3;
 
private​ ​final​ ​float​​[]​ vertexData;
 
private​ ​int​ offset = 0;
 
 
private​ ObjectBuilder(​int​ sizeInVertices) {
 
vertexData = ​new​ ​float​[sizeInVertices * FLOATS_PER_VERTEX];
 
}

There’s nothing too fancy here so far. We’ve defined a constant to represent how many floats we need for a vertex, an array to hold these vertices, and a variable to keep track of the position in the array ...

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