Game Development Reference
In-Depth Information
Listing 4-50. LoadTexture Function
void LoadTexture(int ResourceId)
{
InputStream is = m_Context.getResources()
.openRawResource(ResourceId);
try
{
m_Bitmap = BitmapFactory.decodeStream(is);
}
finally
{
try
{
is.close();
}
catch(IOException e)
{
Log.e("ERROR - Texture ERROR", "Error in LoadTexture()! ");
}
}
}
You must also set the active texture unit where all the texture-related functions operate. This is done
with the glActiveTexture() function in the SetActiveTextureUnit() function. For our purposes in
this topic, the active texture unit will always be 0 (see Listing 4-51).
Listing 4-51. Setting the Active Texture Unit
static void SetActiveTextureUnit(int UnitNumber)
{
GLES20.glActiveTexture(UnitNumber);
}
In order to select this texture object as the current one, you have to active it by calling
ActivateTexture() . The glBindTexture() is called with the m_TextureId to activate it
(see Listing 4-52).
Listing 4-52. Activating the Texture
void ActivateTexture()
{
// Activate Texture
if (m_TextureId != 0)
{
GLES20.glBindTexture (GLES20.GL_TEXTURE_2D, m_TextureId);
}
else
{
Log.e("ERROR - Texture ERROR- m_TextureId = 0", "Error in ActivateTexture()! ");
}
}
Search WWH ::




Custom Search