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.Color; 21 import com.badlogic.gdx.graphics.GL20; 22 import com.badlogic.gdx.graphics.OrthographicCamera; 23 import com.badlogic.gdx.graphics.Pixmap; 24 import com.badlogic.gdx.graphics.Texture; 25 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 26 import com.badlogic.gdx.tests.utils.GdxTest; 27 28 public class PixelPerfectTest extends GdxTest { 29 SpriteBatch batch; 30 OrthographicCamera cam; 31 Texture tex; 32 33 @Override 34 public void create () { 35 Pixmap pixmap = new Pixmap(16, 16, Pixmap.Format.RGBA8888); 36 pixmap.setColor(Color.BLUE); 37 pixmap.fill(); 38 pixmap.setColor(Color.RED); 39 pixmap.drawLine(0, 0, 15, 15); 40 pixmap.drawLine(0, 15, 15, 0); 41 42 tex = new Texture(pixmap); 43 batch = new SpriteBatch(); 44 cam = new OrthographicCamera(); 45 cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 46 } 47 48 @Override 49 public void resize (int width, int height) { 50 cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 51 } 52 53 @Override 54 public void render () { 55 Gdx.gl.glClearColor(1, 0, 1, 1); 56 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 57 cam.update(); 58 batch.setProjectionMatrix(cam.combined); 59 batch.begin(); 60 batch.draw(tex, 1, 1); 61 batch.end(); 62 } 63 } 64