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

Loading in the Height Map

To load the height map into OpenGL, we need to load in the image data and convert it into a set of vertices, one for each pixel. Each vertex will have a position based on its position in the image and a height based on the brightness of the pixel. Once we have all of the vertices loaded in, we’ll use the index buffer to group them into triangles that we can draw with OpenGL.

Generating the Vertex Data

Let’s create a new class called Heightmap in the com.particles.android.objects package, adding the following code inside the class to start out:

Heightmap/src/com/particles/android/objects/Heightmap.java
 
private​ ​static​ ​final​ ​int​ POSITION_COMPONENT_COUNT = 3;
 
 
private​ ​final​ ​int​ width;
 
private​ ​final​ ​ ...

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