JoglPixmap (int width, int height, Pixmap.Format format) {\r
int internalformat = getInternalFormat(format);\r
pixmap = new BufferedImage(width, height, internalformat);\r
- composite = AlphaComposite.Src;\r
+ Graphics2D g = pixmap.createGraphics();\r
+ g.setComposite(AlphaComposite.Clear);\r
+ g.setColor(new Color(0, 0, 0, 0));\r
+ g.fillRect(0, 0, pixmap.getWidth(), pixmap.getHeight());\r
+ g.dispose();\r
+ composite = AlphaComposite.SrcOver;\r
}\r
\r
JoglPixmap (BufferedImage image) {\r
if (image == null) throw new IllegalArgumentException("image cannot be null.");\r
- pixmap = image;\r
+ pixmap = convert(image);\r
+ }\r
+ \r
+ private BufferedImage convert (BufferedImage image) {\r
+ BufferedImage out = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);\r
+ Graphics2D g = out.createGraphics();\r
+ g.setComposite(AlphaComposite.Clear);\r
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());\r
+ g.setComposite(AlphaComposite.SrcOver);\r
+ g.drawImage(image, 0, 0, null);\r
+ g.dispose();\r
+ return out;\r
}\r
\r
private int getInternalFormat (Pixmap.Format format) {\r
- if (format == Pixmap.Format.RGBA4444 || format == Pixmap.Format.RGBA8888 || format == Pixmap.Format.RGB565)\r
return BufferedImage.TYPE_4BYTE_ABGR;\r
- else\r
- return BufferedImage.TYPE_BYTE_GRAY;\r
}\r
\r
/**\r
--- /dev/null
+package com.badlogic.gdx.tests;\r
+\r
+import java.awt.image.BufferedImage;\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import javax.imageio.ImageIO;\r
+\r
+import com.badlogic.gdx.Files;\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.InputProcessor;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.Pixmap;\r
+import com.badlogic.gdx.graphics.Sprite;\r
+import com.badlogic.gdx.graphics.SpriteBatch;\r
+import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.math.Matrix4;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+\r
+public class PixmapBlendingTesting extends GdxTest {\r
+ private SpriteBatch spriteBatch;\r
+ private Texture text;\r
+ private Sprite logoSprite, test3, test4;\r
+ private Pixmap pixD, pixS1, pixS2;\r
+ \r
+ InputProcessor inputProcessor;\r
+ \r
+ @Override\r
+ public void create () {\r
+ if (spriteBatch != null) return;\r
+ spriteBatch = new SpriteBatch();\r
+\r
+ Matrix4 transform = new Matrix4(); \r
+ transform.setToTranslation(0, Gdx.graphics.getHeight(), 0);\r
+ transform.mul(new Matrix4().setToScaling(1,-1,1));\r
+ spriteBatch.setTransformMatrix(transform); \r
+\r
+ \r
+ pixS1 = Gdx.graphics.newPixmap(Gdx.files.getFileHandle("data/test4.png", Files.FileType.Internal));\r
+ pixS2 = Gdx.graphics.newPixmap(Gdx.files.getFileHandle("data/test3.png", Files.FileType.Internal));\r
+ pixD = Gdx.graphics.newPixmap(64, 128,Pixmap.Format.RGBA8888);\r
+ \r
+ pixD.drawPixmap(pixS1, 0, 0, 0, 0, 76, 76); \r
+ pixD.drawPixmap(pixS2, 0, 0, 0, 0, 76, 76);\r
+ \r
+ try {\r
+ ImageIO.write(((BufferedImage)pixD.getNativePixmap()), ".png", new File("out.png"));\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ logoSprite = new Sprite(Gdx.graphics.newUnmanagedTexture(pixD,\r
+ TextureFilter.Nearest, TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge));\r
+ logoSprite.flip(false, true); \r
+ }\r
+\r
+ @Override\r
+ public void render () {\r
+ \r
+ GL10 gl = Gdx.graphics.getGL10();\r
+ gl.glClearColor(0,1,0,1);\r
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+ \r
+ spriteBatch.begin(); \r
+ logoSprite.draw(spriteBatch);\r
+ spriteBatch.end();\r
+ \r
+ }\r
+\r
+public boolean needsGL20 () {\r
+ return false;\r
+}\r
+}\r