Can somebody tell me how to a png file to a PaletteTexture? I did lots
of research and found glCompressedTexImage2D, but it seems all the
example shows how to generate the palette texture from some hard code
numbers, not from a image file. Can someone show me a code snippet or
a reference? Great appreciate!!

Now, I tried to extract the pixels from a bitmap which generated from
a png file, and then I tried to generated the palette texture from the
extracted pixels. But I can only see the white square, I put the code
here to see anyone helps me!

Bitmap originalBitmap = BitmapFactory.decodeStream(is);

int[] pixels = new
int[originalBitmap.getHeight()*originalBitmap.getWidth()];
originalBitmap.getPixels(pixels, 0, originalBitmap.getWidth(), 0, 0,
originalBitmap.getWidth(), originalBitmap.getHeight());

textureInfo.source = iFile;

gl.glGenTextures(1, textureInfo.textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureInfo.textures[0]);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);


byte[] textureData = new byte[pixels.length];
for (int i = 0; i < textureData.length; i++) {
    textureData[i] = new Integer(pixels[i]).byteValue();
}
int size = textureData.length;

ByteBuffer bb = ByteBuffer.allocateDirect(size);
bb.put(textureData);
bb.position(0);

gl.glCompressedTexImage2D(GL10.GL_TEXTURE_2D, -2,
GL10.GL_PALETTE4_RGB8_OES, originalBitmap.getWidth(), h,
originalBitmap.getHeight(),size, bb);

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to