Drawing Our Texture

Now that we’ve divided our vertex data and shader programs into different classes, let’s update our renderer class to draw using our texture. Open up AirHockeyRenderer, and delete everything except onSurfaceChanged, as that’s the only method we won’t change. Add the following members and constructor:

AirHockeyTextured/src/com/airhockey/android/AirHockeyRenderer.java
 
private​ ​final​ ​Context​ context;
 
 
private​ ​final​ ​float​​[]​ projectionMatrix = ​new​ ​float​[16];
 
private​ ​final​ ​float​​[]​ modelMatrix = ​new​ ​float​[16];
 
 
private​ Table table;
 
private​ Mallet mallet;
 
 
private​ TextureShaderProgram textureProgram;
 
private​ ColorShaderProgram colorProgram;
 
 
private​ ​int​ texture;
 
 
public​ AirHockeyRenderer(​ ...

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.