public static int loadTiledTexture(int file) { GL.glGenTextures(1, singleID, 0); GL.glBindTexture(GL.GL_TEXTURE_2D, singleID[0]); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); InputStream is = Resource.getResInputStream(file); Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(is); } catch (Exception e) { Log.e(TAG, "Could not read texture file " + file, e); return 0; } finally { try { is.close(); } catch (Exception e) { Log.e(TAG, "Error closing stream", e); } } if (bitmap != null) { GLUtils.texImage2D(GL.GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); } else { Log.e(TAG, "Could not read bitmap " + file); return 0; } return singleID[0]; }
public static int createGLResource(int type, int param) { int id = 0; if (type == GL_TEXTURE_OBJECT) { int[] temp = new int[1]; gl.glGenTextures(1, temp, 0); id = temp[0]; glTextureObjects.add(id); } else if (type == GL_VERTEX_BUFFER) { int[] temp = new int[1]; gl.glGenBuffersARB(1, temp, 0); id = temp[0]; glVertexBuffers.add(id); } else if (type == GL_FRAME_BUFFER) { int[] temp = new int[1]; gl.glGenFramebuffersEXT(1, temp, 0); id = temp[0]; glFrameBuffers.add(id); } else if (type == GL_RENDER_BUFFER) { int[] temp = new int[1]; gl.glGenRenderbuffersEXT(1, temp, 0); id = temp[0]; glRenderBuffers.add(id); } else if (type == GLSL_PROGRAM) { id = gl.glCreateProgram(); glslPrograms.add(id); } else if (type == GLSL_SHADER) { id = gl.glCreateShader(param); glslShaders.add(id); } return id; }
public static int loadMipMappedTexture(Bitmap bitmap) { GL.glGenTextures(1, singleID, 0); int textureID = singleID[0]; GL.glBindTexture(GL.GL_TEXTURE_2D, textureID); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); if (autoMipMap) { // To use automatic mipmap generation GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE); GLUtils.texImage2D(GL.GL_TEXTURE_2D, 0, bitmap, 0); return textureID; } // Original code is buggy on certain devices ("HTC Desire S", "Motorola Milestone (Droid) 3 // XT860 Android 2.3.5 Gingerbread") // Need conversion as a workaround Bitmap oldBitmap = bitmap; bitmap = oldBitmap.copy(Bitmap.Config.ARGB_8888, true); if (bitmap == null) return 0; oldBitmap.recycle(); int level = 0; int height = bitmap.getHeight(); int width = bitmap.getWidth(); while (height >= 1 || width >= 1) { // First of all, generate the texture from our bitmap and set it to the according level GLUtils.texImage2D(GL.GL_TEXTURE_2D, level, bitmap, 0); if (height == 1 && width == 1) break; // Increase the mipmap level level++; height /= 2; if (height == 0) height = 1; width /= 2; if (width == 0) width = 1; Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true); // Clean up bitmap.recycle(); bitmap = bitmap2; } return textureID; }
/** * Creates a new texture ID. * * @param gl the GL object associated with the current OpenGL context * @return a new texture ID */ private static int createTextureID(GL gl) { int[] tmp = new int[1]; gl.glGenTextures(1, tmp, 0); return tmp[0]; }
public static int loadTexture(Bitmap bitmap) { GL.glGenTextures(1, singleID, 0); loadTexture(singleID[0], bitmap); return singleID[0]; }
public static int loadTexture(String filePath) { GL.glGenTextures(1, singleID, 0); loadTexture(singleID[0], filePath); return singleID[0]; }
public static int loadTexture(int file) { GL.glGenTextures(1, singleID, 0); loadTexture(singleID[0], file); return singleID[0]; }