OSDN Git Service

[fixed] JoglPixmap compositing now works like LwjglCompositing...
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 13:10:58 +0000 (13:10 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 17 Nov 2010 13:10:58 +0000 (13:10 +0000)
[added] PixmapBlendingTest

backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPixmap.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPixmap.java
tests/gdx-tests-android/assets/data/test3.png [new file with mode: 0644]
tests/gdx-tests-android/assets/data/test4.png [new file with mode: 0644]
tests/gdx-tests-jogl/data/test3.png [new file with mode: 0644]
tests/gdx-tests-jogl/data/test4.png [new file with mode: 0644]
tests/gdx-tests-lwjgl/data/test3.png [new file with mode: 0644]
tests/gdx-tests-lwjgl/data/test4.png [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTesting.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java

index 9c9ecab..632528b 100644 (file)
@@ -38,19 +38,32 @@ final class JoglPixmap implements Pixmap {
        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
index 915ecd5..7bf03b3 100644 (file)
@@ -47,6 +47,7 @@ final class LwjglPixmap implements Pixmap {
        }\r
 \r
        LwjglPixmap (BufferedImage image) {\r
+               if (image == null) throw new IllegalArgumentException("image cannot be null.");\r
                pixmap = convert(image);\r
        }\r
 \r
@@ -62,10 +63,7 @@ final class LwjglPixmap implements Pixmap {
        }\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
        public void drawCircle (int x, int y, int radius) {\r
diff --git a/tests/gdx-tests-android/assets/data/test3.png b/tests/gdx-tests-android/assets/data/test3.png
new file mode 100644 (file)
index 0000000..d35d15d
Binary files /dev/null and b/tests/gdx-tests-android/assets/data/test3.png differ
diff --git a/tests/gdx-tests-android/assets/data/test4.png b/tests/gdx-tests-android/assets/data/test4.png
new file mode 100644 (file)
index 0000000..4e703c8
Binary files /dev/null and b/tests/gdx-tests-android/assets/data/test4.png differ
diff --git a/tests/gdx-tests-jogl/data/test3.png b/tests/gdx-tests-jogl/data/test3.png
new file mode 100644 (file)
index 0000000..d35d15d
Binary files /dev/null and b/tests/gdx-tests-jogl/data/test3.png differ
diff --git a/tests/gdx-tests-jogl/data/test4.png b/tests/gdx-tests-jogl/data/test4.png
new file mode 100644 (file)
index 0000000..4e703c8
Binary files /dev/null and b/tests/gdx-tests-jogl/data/test4.png differ
diff --git a/tests/gdx-tests-lwjgl/data/test3.png b/tests/gdx-tests-lwjgl/data/test3.png
new file mode 100644 (file)
index 0000000..d35d15d
Binary files /dev/null and b/tests/gdx-tests-lwjgl/data/test3.png differ
diff --git a/tests/gdx-tests-lwjgl/data/test4.png b/tests/gdx-tests-lwjgl/data/test4.png
new file mode 100644 (file)
index 0000000..4e703c8
Binary files /dev/null and b/tests/gdx-tests-lwjgl/data/test4.png differ
diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTesting.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTesting.java
new file mode 100644 (file)
index 0000000..774a5e9
--- /dev/null
@@ -0,0 +1,75 @@
+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
index 85f7e43..9791c95 100644 (file)
@@ -29,6 +29,7 @@ import com.badlogic.gdx.tests.Mpg123Test;
 import com.badlogic.gdx.tests.MultitouchTest;\r
 import com.badlogic.gdx.tests.MyFirstTriangle;\r
 import com.badlogic.gdx.tests.ObjTest;\r
+import com.badlogic.gdx.tests.PixmapBlendingTesting;\r
 import com.badlogic.gdx.tests.SpriteSheetTest;\r
 import com.badlogic.gdx.tests.ParticleEmitterTest;\r
 import com.badlogic.gdx.tests.PixelsPerInchTest;\r
@@ -91,6 +92,7 @@ public class GdxTests
                SpriteSheetTest.class,\r
                ParticleEmitterTest.class,\r
                PixelsPerInchTest.class,\r
+               PixmapBlendingTesting.class,\r
                Pong.class,\r
                SimpleTest.class,\r
                SoundTest.class,\r