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

Drawing the Height Map

Now that we have the height map loaded in, let’s get it drawn to the screen. Create a new file called heightmap_vertex_shader.glsl in your /res/raw folder, and add the following code:

Heightmap/res/raw/heightmap_vertex_shader.glsl
 
uniform mat4 u_Matrix;
 
attribute vec3 a_Position;
 
varying vec3 v_Color;
 
 
void​ main()
 
{
 
v_Color = mix(vec3(0.180, 0.467, 0.153), ​// A dark green
 
vec3(0.660, 0.670, 0.680), ​// A stony gray
 
a_Position.y);
 
 
gl_Position = u_Matrix * vec4(a_Position, 1.0);
 
}

This vertex shader uses a new shader function, mix, to smoothly interpolate between two different colors. We set up our height map so that the height is between 0 and 1, and we use this height as the ratio between the two colors. ...

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