Graphics Programs Reference
In-Depth Information
So, to use two 2D textures, two texture objects must be generated, as shown in
List-
ing 5-13
. Each of the texture ids must be bound to the texture type, which, in this
case, is
GL_TEXTURE_2D
. Similarly, other ES 2.0 functions to successfully load the
image data—
glPixelStorei
,
glTexParameter*
and
texImage2D
—must
be separately called for each texture object, regardless of the number of
Bitmap
re-
sources used (
Listing 5-13
).
Listing 5-13.
GL MULTI TEXTURE/src/com/apress/android/glmultitexture/
GLES20Renderer.java
int[] textures = new int[2];
GLES20.glGenTextures(2, textures, 0);
_textureId1 = textures[0];
_textureId2 = textures[1];
// load the 1st texture
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
_textureId1);
InputStream is1 =
_context.getResources().openRawResource(R.drawable.brick1);
Bitmap img1;
try {
img1 = BitmapFactory.decodeStream(is1);
} finally {
try {
is1.close();
} catch(IOException e) {
// e.printStackTrace();
}
}
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); //
GL_LINEAR
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
Search WWH ::
Custom Search