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

Creating a New Set of Shaders

Before we can draw the texture to the screen, we’ll have to create a new set of shaders that will accept a texture and apply it to the fragments being drawn. These new shaders will be similar to the ones we’ve been working with until now, with just a couple of slight changes to add support for texturing.

Creating the New Vertex Shader

Create a new file under your project’s /res/raw/ directory, and call it texture_vertex_shader.glsl. Add the following contents:

AirHockeyTextured/res/raw/texture_vertex_shader.glsl
 
uniform mat4 u_Matrix;
 
 
attribute vec4 a_Position;
 
attribute vec2 a_TextureCoordinates;
 
 
varying vec2 v_TextureCoordinates;
 
 
void​ main()
 
{
 
v_TextureCoordinates = a_TextureCoordinates;
 
gl_Position ...

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