Home | History | Annotate | Download | only in tests
      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.OrthographicCamera;
     22 import com.badlogic.gdx.graphics.Pixmap;
     23 import com.badlogic.gdx.graphics.Pixmap.Format;
     24 import com.badlogic.gdx.graphics.Texture;
     25 import com.badlogic.gdx.graphics.g2d.BitmapFont;
     26 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
     27 import com.badlogic.gdx.graphics.glutils.ETC1;
     28 import com.badlogic.gdx.graphics.glutils.ETC1.ETC1Data;
     29 import com.badlogic.gdx.tests.utils.GdxTest;
     30 import com.badlogic.gdx.tests.utils.OrthoCamController;
     31 
     32 public class ETC1Test extends GdxTest {
     33 	OrthographicCamera camera;
     34 	OrthoCamController controller;
     35 	Texture img1;
     36 	Texture img2;
     37 	SpriteBatch batch;
     38 	BitmapFont font;
     39 
     40 	@Override
     41 	public void create () {
     42 		font = new BitmapFont();
     43 		camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     44 		controller = new OrthoCamController(camera);
     45 		Gdx.input.setInputProcessor(controller);
     46 
     47 		Pixmap pixmap = new Pixmap(32, 32, Format.RGB565);
     48 		pixmap.setColor(1, 0, 0, 1);
     49 		pixmap.fill();
     50 		pixmap.setColor(0, 1, 0, 1);
     51 		pixmap.drawLine(0, 0, 32, 32);
     52 		pixmap.drawLine(0, 32, 32, 0);
     53 		ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap);
     54 		pixmap.dispose();
     55 		pixmap = ETC1.decodeImage(encodedImage, Format.RGB565);
     56 		encodedImage.dispose();
     57 
     58 		img1 = new Texture(pixmap);
     59 		img2 = new Texture("data/test.etc1");
     60 		batch = new SpriteBatch();
     61 		pixmap.dispose();
     62 	}
     63 
     64 	@Override
     65 	public void render () {
     66 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     67 
     68 		camera.update();
     69 
     70 		batch.setProjectionMatrix(camera.combined);
     71 		batch.begin();
     72 		batch.draw(img2, -100, 0);
     73 		batch.draw(img1, 0, 0);
     74 		batch.end();
     75 
     76 		batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     77 		batch.begin();
     78 		font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 0, 30);
     79 		batch.end();
     80 	}
     81 
     82 	@Override
     83 	public void dispose () {
     84 		batch.dispose();
     85 		font.dispose();
     86 		img1.dispose();
     87 		img2.dispose();
     88 	}
     89 }
     90