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​ ​ ...

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.