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 Textures into OpenGL

Our first task will be to load data from an image file into an OpenGL texture. To start out, let’s create a new class in the com.airhockey.android.util package called TextureHelper. We’ll begin with the following method signature:

AirHockeyTextured/src/com/airhockey/android/util/TextureHelper.java
 
public​ ​static​ ​int​ loadTexture(​Context​ context, ​int​ resourceId) {

This method will take in an Android context and a resource ID and will return the ID of the loaded OpenGL texture. To start off, we’ll generate a new texture ID using the same type of pattern as when we’ve created other OpenGL objects:

AirHockeyTextured/src/com/airhockey/android/util/TextureHelper.java
 
final​ ​int​​[]​ textureObjectIds = ​new​ ​ ...

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