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