desktop: fix awt bitmap to texture

This commit is contained in:
Hannes Janetzek 2013-07-01 04:12:35 +02:00
parent d87376353c
commit ead0594d81
2 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,6 @@ import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.utils.BufferUtils;
public class AwtBitmap implements Bitmap {
BufferedImage bitmap;
int width;
int height;
@ -28,6 +27,7 @@ public class AwtBitmap implements Bitmap {
}
AwtBitmap(InputStream inputStream) throws IOException {
this.bitmap = ImageIO.read(inputStream);
this.width = this.bitmap.getWidth();
this.height = this.bitmap.getHeight();
@ -62,20 +62,24 @@ public class AwtBitmap implements Bitmap {
int[] pixels;
IntBuffer buffer;
if (width == 512 && height == 256) {
if (width * height < 512 * 256) {
pixels = tmpPixel;
buffer = tmpBuffer;
buffer.clear();
//Log.d("AwtBitmap", "default texture");
} else {
pixels = new int[width * height];
buffer = BufferUtils.newIntBuffer(width * height);
//Log.d("AwtBitmap", "create texture buffer " + width + "x" + height);
}
bitmap.getRGB(0, 0, width, height, pixels, 0, width);
buffer.put(pixels);
for (int i = 0, n = width * height; i < n; i++){
int c = pixels[i];
// flip blue with red - silly Java
pixels[i] = (c & 0xff00ff00) | (c & 0x00ff0000) >>> 16 | (c & 0x000000ff) << 16;
}
buffer.put(pixels, 0, width * height);
buffer.flip();
Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width,

View File

@ -28,8 +28,6 @@ import java.util.Map;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Paint;
import com.badlogic.gdx.Gdx;
public class AwtPaint implements Paint {
private static int getCap(Cap cap) {