Esempio n. 1
0
  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];
  }
Esempio n. 2
0
 public static int loadMipMappedTexture(int file) {
   InputStream is = Resource.getResInputStream(file);
   Bitmap bitmap = null;
   try {
     // Log.d(TAG, "ETC1 Support: " + ETC1Util.isETC1Supported());
     BitmapFactory.Options opts = new BitmapFactory.Options();
     opts.inScaled = false;
     // opts.inPreferredConfig = Bitmap.Config.RGB_565;
     bitmap = BitmapFactory.decodeStream(is, null, opts); // decodeStream(is, opts);
     return loadMipMappedTexture(bitmap);
   } 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);
     }
   }
 }
Esempio n. 3
0
  public static boolean loadTexture(int glId, String filePath) {

    InputStream is = Resource.getResInputStream(filePath);
    if (is == null) return false;
    Bitmap bitmap = null;
    try {
      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inScaled = false;
      // opts.inPreferredConfig = Bitmap.Config.RGB_565;
      bitmap = BitmapFactory.decodeStream(is, null, opts);
    } catch (Exception e) {
      Log.e(TAG, "Could not read texture file " + filePath, e);
      return false;
    } finally {
      try {
        is.close();
      } catch (Exception e) {
        Log.e(TAG, "Error closing stream", e);
      }
    }

    return loadTexture(glId, bitmap);
  }