1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Gdx; 20 import com.badlogic.gdx.graphics.GL20; 21 import com.badlogic.gdx.graphics.Pixmap; 22 import com.badlogic.gdx.graphics.Texture; 23 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 24 import com.badlogic.gdx.graphics.g2d.TextureRegion; 25 import com.badlogic.gdx.tests.utils.GdxTest; 26 27 public class PixmapTest extends GdxTest { 28 Pixmap pixmap; 29 Texture texture; 30 SpriteBatch batch; 31 TextureRegion region; 32 create()33 public void create () { 34 // Create an empty dynamic pixmap 35 pixmap = new Pixmap(800, 480, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); 36 37 // Create a texture to contain the pixmap 38 texture = new Texture(1024, 1024, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); 39 texture.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear); 40 texture.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge); 41 42 pixmap.setColor(1.0f, 0.0f, 0.0f, 1.0f); // Red 43 pixmap.drawLine(0, 0, 100, 100); 44 45 pixmap.setColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue 46 pixmap.drawLine(100, 100, 200, 0); 47 48 pixmap.setColor(0.0f, 1.0f, 0.0f, 1.0f); // Green 49 pixmap.drawLine(100, 0, 100, 100); 50 51 pixmap.setColor(1.0f, 1.0f, 1.0f, 1.0f); // White 52 pixmap.drawCircle(400, 300, 100); 53 54 // Blit the composited overlay to a texture 55 texture.draw(pixmap, 0, 0); 56 region = new TextureRegion(texture, 0, 0, 800, 480); 57 batch = new SpriteBatch(); 58 59 Pixmap pixmap = new Pixmap(512, 1024, Pixmap.Format.RGBA8888); 60 for (int y = 0; y < pixmap.getHeight(); y++) { // 1024 61 for (int x = 0; x < pixmap.getWidth(); x++) { // 512 62 pixmap.getPixel(x, y); 63 } 64 } 65 pixmap.dispose(); 66 } 67 render()68 public void render () { 69 Gdx.gl.glClearColor(0.6f, 0.6f, 0.6f, 1); 70 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 71 batch.begin(); 72 batch.draw(region, 0, 0); 73 batch.end(); 74 } 75 } 76