\r
public class Gdx2DTest extends GdxTest { \r
SpriteBatch batch;\r
- List<Sprite> sprites; \r
- \r
- Gdx2DPixmap createPixmap(int width, int height, int format) {\r
- return Gdx2DPixmap.newPixmap(width, height, format);\r
- }\r
+ List<Sprite> sprites; \r
\r
Texture textureFromPixmap(Gdx2DPixmap pixmap) {\r
Texture texture = Gdx.graphics.newUnmanagedTexture(pixmap.getWidth(), pixmap.getHeight(), Format.RGB565, TextureFilter.Nearest, TextureFilter.Nearest, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
return texture;\r
}\r
\r
- @Override public void create () { \r
- batch = new SpriteBatch();\r
- sprites = new ArrayList<Sprite>();\r
- Gdx2DPixmap alpha = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_ALPHA); \r
- Gdx2DPixmap luminanceAlpha = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_LUMINANCE_ALPHA); \r
- Gdx2DPixmap rgb565 = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_RGB565);\r
- Gdx2DPixmap rgba4444 = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_RGBA4444); \r
- Gdx2DPixmap rgb888 = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_RGB888); \r
- Gdx2DPixmap rgba8888 = createPixmap(32, 32, Gdx2DPixmap.GDX2D_FORMAT_RGBA8888);\r
- Gdx2DPixmap composite = createPixmap(256, 64, Gdx2DPixmap.GDX2D_FORMAT_RGB565);\r
- \r
- Gdx2DPixmap.setBlend(1);\r
- \r
- alpha.clear(Color.rgba8888(1, 1, 1, 0.1f));\r
- alpha.setPixel(16, 16, Color.rgba8888(1, 1, 1, 1)); \r
-// if(alpha.getPixel(16, 16) != Color.rgba8888(1, 1, 1, 1f)) throw new RuntimeException("alpha error");\r
-// if(alpha.getPixel(15, 16) != Color.rgba8888(1, 1, 1, 0.1f)) throw new RuntimeException("alpha error");\r
- alpha.drawLine(0, 0, 31, 31, Color.rgba8888(1, 1, 1, 1));\r
- alpha.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 1, 0.5f)); \r
- alpha.fillRect(20, 10, 5, 7, Color.rgba8888(1, 1, 1, 0.5f));\r
- alpha.drawCircle(16, 16, 10, Color.rgba8888(1, 1, 1, 1));\r
- alpha.fillCircle(16, 16, 6, Color.rgba8888(1, 1, 1, 1));\r
- \r
- luminanceAlpha.clear(Color.rgba8888(1, 1, 1, 0.1f));\r
- luminanceAlpha.setPixel(16, 16, Color.rgba8888(1, 1, 1.0f, 1.0f));\r
-// if(luminanceAlpha.getPixel(16, 16) != Color.rgba8888(1, 1, 1, 1)) throw new RuntimeException("luminance alpha error");\r
-// if(luminanceAlpha.getPixel(15, 16) != Color.rgba8888(1, 1, 1, 0.1f)) throw new RuntimeException("luminance alpha error");\r
- luminanceAlpha.drawLine(0, 0, 31, 31, Color.rgba8888(1, 1, 1, 1));\r
- luminanceAlpha.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 1, 0.5f));\r
- luminanceAlpha.fillRect(20, 10, 5, 7, Color.rgba8888(1, 1, 1, 0.5f));\r
- luminanceAlpha.drawCircle(16, 16, 10, Color.rgba8888(1, 1, 1, 1));\r
- luminanceAlpha.fillCircle(16, 16, 6, Color.rgba8888(1, 1, 1, 1));\r
- \r
- rgb565.clear(Color.rgba8888(1, 0, 0, 1));\r
- rgb565.setPixel(16, 16, Color.rgba8888(0, 0, 1, 1));\r
-// if(rgb565.getPixel(16, 16) != Color.rgba8888(0, 0, 1, 1)) throw new RuntimeException("rgb565 error");\r
-// if(rgb565.getPixel(31, 31) != Color.rgba8888(1, 0, 0, 1)) throw new RuntimeException("rgb565 error");\r
- rgb565.drawLine(0,0,32,32, Color.rgba8888(0, 1, 0, 1));\r
- rgb565.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 0, 0.5f));\r
- rgb565.fillRect(20, 10, 5, 7, Color.rgba8888(0, 1, 1, 0.5f));\r
- rgb565.drawCircle(16, 16, 10, Color.rgba8888(1, 0, 1, 1));\r
- rgb565.fillCircle(16, 16, 6, Color.rgba8888(1, 0, 1, 1));\r
+ void drawToPixmap(Gdx2DPixmap pixmap) {\r
+ pixmap.clear(Color.rgba8888(1, 0, 0, 0.1f));\r
+ pixmap.setPixel(16, 16, Color.rgba8888(0, 0, 1, 1));\r
+ int clearColor = 0;\r
+ int pixelColor = 0;\r
+ switch(pixmap.getFormat()) {\r
+ case Gdx2DPixmap.GDX2D_FORMAT_ALPHA:\r
+ clearColor = Color.rgba8888(1, 1, 1, 0.1f);\r
+ pixelColor = Color.rgba8888(1, 1, 1, 1);\r
+ break;\r
+ case Gdx2DPixmap.GDX2D_FORMAT_LUMINANCE_ALPHA:\r
+ clearColor = 0x36363619; //Color.rgba8888(1, 1, 1, 0.1f);\r
+ pixelColor = 0xffffff12;\r
+ break;\r
+ case Gdx2DPixmap.GDX2D_FORMAT_RGB565:\r
+ clearColor = Color.rgba8888(1, 0, 0, 1); \r
+ pixelColor = Color.rgba8888(0, 0, 1, 1);\r
+ break;\r
+ case Gdx2DPixmap.GDX2D_FORMAT_RGB888:\r
+ clearColor = Color.rgba8888(1, 0, 0, 1); \r
+ pixelColor = Color.rgba8888(0, 0, 1, 1);\r
+ break;\r
+ case Gdx2DPixmap.GDX2D_FORMAT_RGBA4444:\r
+ clearColor = 0xff000011; \r
+ pixelColor = Color.rgba8888(0, 0, 1, 1);\r
+ break;\r
+ case Gdx2DPixmap.GDX2D_FORMAT_RGBA8888:\r
+ clearColor = Color.rgba8888(1, 0, 0, 0.1f);\r
+ pixelColor = Color.rgba8888(0, 0, 1, 1);\r
+ \r
+ } \r
+ if(pixmap.getPixel(15, 16) != clearColor) throw new RuntimeException("error clear: " + pixmap.getFormatString()); \r
+ if(pixmap.getPixel(16, 16) != pixelColor) throw new RuntimeException("error pixel: " + pixmap.getFormatString()); \r
+ pixmap.drawLine(0,0,31,31,Color.rgba8888(1, 1, 1, 1));\r
+ pixmap.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 0, 0.5f));\r
+ pixmap.fillRect(20, 10, 5, 7, Color.rgba8888(0, 1, 1, 0.5f));\r
+ pixmap.drawCircle(16, 16, 10, Color.rgba8888(1, 0, 1, 1));\r
+ pixmap.fillCircle(16, 16, 6, Color.rgba8888(0, 1, 0, 0.5f));\r
+ pixmap.drawLine(-10, -10, 0, 0, Color.rgba8888(1, 1, 0, 1));\r
+ pixmap.drawLine(41, -10, 31, 0, Color.rgba8888(1, 1, 0, 1));\r
+ pixmap.drawLine(10, 41, 0, 31, Color.rgba8888(0, 1, 1, 1));\r
+ pixmap.drawLine(41, 41, 31, 31, Color.rgba8888(0, 1, 1, 1)); \r
\r
- rgba4444.clear(Color.rgba8888(1, 0, 0, 1));\r
- rgba4444.setPixel(16, 16, Color.rgba8888(0, 0, 1, 1));\r
-// if(rgba4444.getPixel(16, 16) != Color.rgba8888(0, 0, 1, 1)) throw new RuntimeException("rgba4444 error");\r
-// if(rgba4444.getPixel(15, 16) != 0xff0000ff) throw new RuntimeException("rgba4444 error"); // lut will not be 100% correct\r
- rgba4444.drawLine(0,0,31,31, Color.rgba8888(0, 1, 0, 1));\r
- rgba4444.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 0, 0.5f));\r
- rgba4444.fillRect(20, 10, 5, 7, Color.rgba8888(0, 1, 1, 0.5f));\r
- rgba4444.drawCircle(16, 16, 10, Color.rgba8888(1, 0, 1, 1));\r
- rgba4444.fillCircle(16, 16, 6, Color.rgba8888(1, 0, 1, 0.5f));\r
+ pixmap.drawRect(-10, -10, 20, 20, Color.rgba8888(0, 1, 1, 1)); \r
+ pixmap.drawRect(21, -10, 20, 20, Color.rgba8888(0, 1, 1, 1));\r
+ pixmap.drawRect(-10, 21, 20, 20, Color.rgba8888(0, 1, 1, 1));\r
+ pixmap.drawRect(21, 21, 20, 20, Color.rgba8888(0, 1, 1, 1));\r
\r
- rgb888.clear(Color.rgba8888(1, 0, 0, 1));\r
- rgb888.setPixel(16, 16, Color.rgba8888(0, 0, 1, 1));\r
-// if(rgb888.getPixel(16, 16) != Color.rgba8888(0, 0, 1, 1)) throw new RuntimeException("rgb888 error");\r
-// if(rgb888.getPixel(15, 16) != Color.rgba8888(1, 0, 0, 1)) throw new RuntimeException("rgb888 error");\r
- rgb888.drawLine(0,0,31,31, Color.rgba8888(0, 1, 0, 1));\r
- rgb888.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 0, 0.5f));\r
- rgb888.fillRect(20, 10, 5, 7, Color.rgba8888(0, 1, 1, 0.5f));\r
- rgb888.drawCircle(16, 16, 10, Color.rgba8888(1, 0, 1, 1));\r
- rgb888.fillCircle(16, 16, 6, Color.rgba8888(1, 0, 1, 1));\r
- \r
- rgba8888.clear(Color.rgba8888(1, 0, 0, 1));\r
- rgba8888.setPixel(16, 16, Color.rgba8888(0, 0, 1, 1));\r
-// if(rgba8888.getPixel(16, 16) != Color.rgba8888(0, 0, 1, 1)) throw new RuntimeException("rgba8888 error");\r
-// if(rgba8888.getPixel(15, 16) != Color.rgba8888(1, 0, 0, 1)) throw new RuntimeException("rgba8888 error");\r
- rgba8888.drawLine(0,0,31,31,Color.rgba8888(0, 1, 0, 1));\r
- rgba8888.drawRect(10, 10, 5, 7, Color.rgba8888(1, 1, 0, 0.5f));\r
- rgba8888.fillRect(20, 10, 5, 7, Color.rgba8888(0, 1, 1, 0.5f));\r
- rgba8888.drawCircle(16, 16, 10, Color.rgba8888(1, 0, 1, 1));\r
- rgba8888.fillCircle(16, 16, 6, Color.rgba8888(1, 0, 1, 0.5f));\r
+ pixmap.fillRect(-10, -10, 20, 20, Color.rgba8888(0, 1, 1, 0.5f)); \r
+ pixmap.fillRect(21, -10, 20, 20, Color.rgba8888(0, 1, 1, 0.5f));\r
+ pixmap.fillRect(-10, 21, 20, 20, Color.rgba8888(0, 1, 1, 0.5f));\r
+ pixmap.fillRect(21, 21, 20, 20, Color.rgba8888(0, 1, 1, 0.5f));\r
+ }\r
+ \r
+ Gdx2DPixmap[] testPixmaps() {\r
+ int[] formats = { Gdx2DPixmap.GDX2D_FORMAT_ALPHA, \r
+ Gdx2DPixmap.GDX2D_FORMAT_LUMINANCE_ALPHA,\r
+ Gdx2DPixmap.GDX2D_FORMAT_RGB565,\r
+ Gdx2DPixmap.GDX2D_FORMAT_RGB888,\r
+ Gdx2DPixmap.GDX2D_FORMAT_RGBA4444,\r
+ Gdx2DPixmap.GDX2D_FORMAT_RGBA8888 };\r
\r
- Gdx2DPixmap.setBlend(0);\r
- Gdx2DPixmap.setScale(Gdx2DPixmap.GDX2D_SCALE_LINEAR);\r
- composite.clear(Color.rgba8888(1, 1, 1, 1));\r
- composite.drawPixmap(alpha, 0, 0, 0, 0, 32, 32);\r
- composite.drawPixmap(luminanceAlpha, 0, 0, 32, 0, 32, 32);\r
- composite.drawPixmap(rgb565, 0, 0, 64, 0, 32, 32);\r
- composite.drawPixmap(rgba4444, 0, 0, 96, 0, 32, 32);\r
- composite.drawPixmap(rgb888, 0, 0, 128, 0, 32, 32);\r
- composite.drawPixmap(rgba8888, 0, 0, 160, 0, 32, 32);\r
- composite.drawPixmap(rgb888, 0, 0, 32, 32, 192, 0, 64, 64);\r
- composite.drawPixmap(alpha, 0, 0, 32, 32, 192, 0, 16, 16);\r
- composite.drawPixmap(luminanceAlpha, 0, 0, 32, 32, 256 - 16, 0, 16, 16);\r
- composite.drawPixmap(rgb565, 0, 0, 32, 32, 192, 64 - 16, 16, 16);\r
- composite.drawPixmap(rgba4444, 0, 0, 32, 32, 256 - 16, 64 - 16, 16, 16);\r
- \r
-// Format[] formats = { Format.Alpha, Format.RGB565, Format.RGBA4444, Format.RGBA8888 };\r
-// int[] gdxFormats = { Gdx2DPixmap.GDX2D_FORMAT_ALPHA, Gdx2DPixmap.GDX2D_FORMAT_RGB565, Gdx2DPixmap.GDX2D_FORMAT_RGBA4444, Gdx2DPixmap.GDX2D_FORMAT_RGBA8888 };\r
-// for(int format = 0; format < formats.length; format++) {\r
-// Gdx2DPixmap gdxPixmap = Gdx2DPixmap.newPixmap(256, 256, gdxFormats[format]);\r
-// Pixmap pixmap = Gdx.graphics.newPixmap(256, 256, formats[format]);\r
-// Random rand = new Random(0);\r
-// Random rand2 = new Random(0);\r
-// final int RUNS = 1000;\r
-// long startTime = System.nanoTime(); \r
-// for(int i = 0; i < RUNS; i++) {\r
-//// gdxPixmap.clear(0xffffffff);\r
-// gdxPixmap.drawLine((int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), \r
-// (int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), 0xffffffff);\r
-// gdxPixmap.drawCircle(((int)rand.nextFloat()*256), ((int)rand.nextFloat()*256), ((int)rand.nextFloat() * 128), 0xffffffff);\r
-// gdxPixmap.drawRect((int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), \r
-// (int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), 0xffffffff);\r
-// gdxPixmap.fillCircle(((int)rand.nextFloat()*256), ((int)rand.nextFloat()*256), ((int)rand.nextFloat() * 128), 0xffffffff);\r
-// gdxPixmap.fillRect((int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), \r
-// (int)(rand.nextFloat()*256), ((int)rand.nextFloat()*256), 0xffffffff);\r
-// }\r
-// Gdx.app.log("Gdx2DTest", "format: " + gdxPixmap.getFormatString());\r
-// Gdx.app.log("Gdx2DTest", "gdx2d: " + (System.nanoTime()-startTime) / 1000000000.0f);\r
-// \r
-// startTime = System.nanoTime(); \r
-// for(int i = 0; i < RUNS; i++) {\r
-// pixmap.setColor(1, 1, 1, 1);\r
-//// pixmap.fill();\r
-// pixmap.setColor(1, 1, 1, 1);\r
-// pixmap.drawLine((int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256), \r
-// (int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256));\r
-// pixmap.drawCircle(((int)rand2.nextFloat()*256), ((int)rand2.nextFloat()*256), ((int)rand2.nextFloat() * 128));\r
-// pixmap.drawRectangle((int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256), \r
-// (int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256));\r
-// pixmap.fillCircle(((int)rand2.nextFloat()*256), ((int)rand2.nextFloat()*256), ((int)rand2.nextFloat() * 128));\r
-// pixmap.fillRectangle((int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256), \r
-// (int)(rand2.nextFloat()*256), ((int)rand2.nextFloat()*256));\r
-// }\r
-// Gdx.app.log("Gdx2DTest", "native: " + (System.nanoTime()-startTime) / 1000000000.0f);\r
-// pixmap.dispose();\r
-// gdxPixmap.dispose();\r
-// }\r
+ Gdx2DPixmap[] pixmaps = new Gdx2DPixmap[formats.length];\r
+ for(int i = 0; i < pixmaps.length; i++) {\r
+ Gdx2DPixmap pixmap = new Gdx2DPixmap(32, 32, formats[i]);\r
+ drawToPixmap(pixmap);\r
+ pixmaps[i] = pixmap;\r
+ }\r
+ return pixmaps;\r
+ }\r
+ \r
+ @Override public void create () { \r
+ batch = new SpriteBatch();\r
+ sprites = new ArrayList<Sprite>(); \r
+ Gdx2DPixmap[] pixmaps = testPixmaps();\r
\r
- sprites.add(new Sprite(textureFromPixmap(alpha))); \r
- sprites.add(new Sprite(textureFromPixmap(luminanceAlpha)));\r
- sprites.add(new Sprite(textureFromPixmap(rgb565)));\r
- sprites.add(new Sprite(textureFromPixmap(rgba4444)));\r
- sprites.add(new Sprite(textureFromPixmap(rgb888)));\r
- sprites.add(new Sprite(textureFromPixmap(rgba8888)));\r
- sprites.add(new Sprite(textureFromPixmap(composite))); \r
+ Gdx2DPixmap composite = new Gdx2DPixmap(512, 256, Gdx2DPixmap.GDX2D_FORMAT_RGBA8888);\r
\r
+ Gdx2DPixmap.setBlend(Gdx2DPixmap.GDX2D_BLEND_NONE);\r
+ for(int i = 0; i < pixmaps.length; i++) {\r
+ Gdx2DPixmap.setScale(Gdx2DPixmap.GDX2D_SCALE_NEAREST); \r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64); \r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16);\r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 0, 64, 64);\r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 64, 16, 16);\r
+ Gdx2DPixmap.setScale(Gdx2DPixmap.GDX2D_SCALE_LINEAR);\r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64); \r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16);\r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 100, 64, 64);\r
+ composite.drawPixmap(pixmaps[i], 0, 0, 32, 32, i * 64, 164, 16, 16);\r
+ Sprite sprite = new Sprite(textureFromPixmap(pixmaps[i]));\r
+ sprite.setPosition(10 + i * 32, 10);\r
+ sprites.add(sprite);\r
+ } \r
\r
- sprites.get(0).setPosition(10, 10);\r
- sprites.get(1).setPosition(50, 10);\r
- sprites.get(2).setPosition(90, 10);\r
- sprites.get(3).setPosition(130, 10);\r
- sprites.get(4).setPosition(170, 10);\r
- sprites.get(5).setPosition(210, 10);\r
- sprites.get(6).setPosition(10, 50);\r
+ Sprite sprite = new Sprite(textureFromPixmap(composite));\r
+ sprite.setPosition(10, 50);\r
+ sprites.add(sprite);\r
}\r
\r
@Override public void render() {\r
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);\r
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
- batch.disableBlending();\r
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); \r
batch.begin();\r
for(int i = 0; i < sprites.size(); i++) {\r
sprites.get(i).draw(batch);\r