List of usage examples for android.opengl GLUtils texImage2D
public static void texImage2D(int target, int level, int internalformat, Bitmap bitmap, int type, int border)
From source file:Main.java
public static int loadTexture(Resources resources, int resource, int internalFormat, boolean flip) { int[] textures = s_LOAD_TEXTURE_ID.get(); if (textures == null) { textures = new int[1]; s_LOAD_TEXTURE_ID.set(textures); }/* w w w . j a v a 2 s. co m*/ glActiveTexture(GL_TEXTURE0); glGenTextures(1, textures, 0); int texture = textures[0]; glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); Bitmap bitmap = BitmapFactory.decodeResource(resources, resource); final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); if (flip) { Matrix matrix = new Matrix(); matrix.setScale(1, -1); matrix.postTranslate(0, height); Bitmap flipBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); bitmap.recycle(); bitmap = flipBitmap; } GLUtils.texImage2D(GL_TEXTURE_2D, 0, internalFormat, bitmap, GL_UNSIGNED_BYTE, 0); bitmap.recycle(); glBindTexture(GL_TEXTURE_2D, 0); return texture; }