SHARE
TWEET

Untitled

a guest Jan 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static int loadCompressedTexture(final Context context, final int resourceId){
  2.         final int[] textureHandle = new int[1];
  3.         GLES20.glGenTextures(1, textureHandle, 0);
  4.  
  5.         if (textureHandle[0] != 0){
  6.             InputStream input = context.getResources().openRawResource(resourceId);
  7.  
  8.             GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
  9.  
  10.             GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
  11.             GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  12.  
  13.             try{
  14.                 ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D, 0, 0,GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, input);
  15.             }
  16.             catch(IOException e){
  17.                 System.out.println("DEBUG! IOException"+e.getMessage());
  18.             }
  19.             finally{
  20.                 try {
  21.                     input.close();
  22.                 } catch (IOException e) {
  23.                     // ignore exception thrown from close.
  24.                 }
  25.             }      
  26.             //GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  27.  
  28.             checkGlError("");
  29.         }
  30.         else
  31.             throw new RuntimeException("Error loading texture.");
  32.  
  33.         return textureHandle[0];
  34.     }
  35.    
  36. public static int loadTexture(final Context context, final int resourceId)
  37. {
  38.     final int[] textureHandle = new int[1];
  39.  
  40.     GLES20.glGenTextures(1, textureHandle, 0);
  41.  
  42.     if (textureHandle[0] != 0)
  43.     {
  44.         final BitmapFactory.Options options = new BitmapFactory.Options();
  45.         options.inScaled = false;   // No pre-scaling
  46.         final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
  47.  
  48.         GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
  49.  
  50.         GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_NEAREST);
  51.         GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  52.  
  53.         GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
  54.  
  55.         GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  56.  
  57.         logHeap();
  58.  
  59.         bitmap.recycle();                      
  60.     }
  61.  
  62.     if (textureHandle[0] == 0)
  63.     {
  64.         throw new RuntimeException("Error loading texture.");
  65.     }
  66.  
  67.     return textureHandle[0];
  68. }
  69.    
  70. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
  71. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  72.    
  73. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,  GLES20.GL_LINEAR_MIPMAP_LINEAR);
  74. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,  GLES20.GL_LINEAR);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top