Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.01 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to convert a png file to a PaletteTexture?
  2. Bitmap originalBitmap = BitmapFactory.decodeStream(is);
  3.  
  4. int[] pixels = new int[originalBitmap.getHeight()*originalBitmap.getWidth()];
  5. originalBitmap.getPixels(pixels, 0, originalBitmap.getWidth(), 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight());
  6.  
  7. textureInfo.source = iFile;
  8.  
  9. gl.glGenTextures(1, textureInfo.textures, 0);
  10. gl.glBindTexture(GL10.GL_TEXTURE_2D, textureInfo.textures[0]);
  11.  
  12. gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
  13. gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
  14.  
  15.  
  16. byte[] textureData = new byte[pixels.length];
  17. for (int i = 0; i < textureData.length; i++) {
  18.     textureData[i] = new Integer(pixels[i]).byteValue();
  19. }
  20. int size = textureData.length;
  21.  
  22. ByteBuffer bb = ByteBuffer.allocateDirect(size);
  23. bb.put(textureData);
  24. bb.position(0);
  25.  
  26. gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, -2, GL10.GL_PALETTE4_RGB8_OES, originalBitmap.getWidth(), h, originalBitmap.getHeight(),size, bb);