Ejemplo n.º 1
0
  private void load() {
    GL10 gl = glGraphics.getGL();
    int[] textureIds = new int[1];
    gl.glGenTextures(1, textureIds, 0);
    textureId = textureIds[0];

    InputStream in = null;
    try {
      in = fileIO.readAsset(fileName);
      Bitmap bitmap = BitmapFactory.decodeStream(in);
      if (mipmapped) {
        createMipmaps(gl, bitmap);
      } else {
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
        setFilters(GL10.GL_NEAREST, GL10.GL_NEAREST);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        width = bitmap.getWidth();
        height = bitmap.getHeight();
        bitmap.recycle();
      }
    } catch (IOException e) {
      throw new RuntimeException("Couldn't load texture '" + fileName + "'", e);
    } finally {
      if (in != null)
        try {
          in.close();
        } catch (IOException e) {
        }
    }
  }
Ejemplo n.º 2
0
  private void createMipmaps(GL10 gl, Bitmap bitmap) {
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
    width = bitmap.getWidth();
    height = bitmap.getHeight();
    setFilters(GL10.GL_LINEAR_MIPMAP_NEAREST, GL10.GL_LINEAR);

    int level = 0;
    int newWidth = width;
    int newHeight = height;
    while (true) {
      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
      newWidth = newWidth / 2;
      newHeight = newHeight / 2;
      if (newWidth <= 0) break;

      Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
      bitmap.recycle();
      bitmap = newBitmap;
      level++;
    }

    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    bitmap.recycle();
  }
Ejemplo n.º 3
0
 public void reload() {
   load();
   bind();
   setFilters(minFilter, magFilter);
   glGraphics.getGL().glBindTexture(GL10.GL_TEXTURE_2D, 0);
 }