Creating a Cube
For our next task, we’re going to create a new cube object for our skybox, and we’ll also create our first index array. A cube is a good candidate for indexing because it only has 8 unique vertices. With 3 position components per vertex, we’ll need 24 floats to store these vertices.
Let’s say that we decide to draw the cube with 2 triangles per face, so we have 12 triangles in all. With 3 vertices per triangle, if we were drawing the cube with a vertex array alone, we’d need 36 vertices or 108 floats, with a lot of the data duplicated. With an index array, we don’t need to repeat all of the vertex data. Instead, we only need to repeat the indices. This allows us to reduce the overall size of the data.
Let’s create a new class ...
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.