Search in sources :

Example 6 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class AssetManagerTest method load.

private void load() {
    // Gdx.app.setLogLevel(Logger.DEBUG);
    start = TimeUtils.nanoTime();
    tex1 = new Texture("data/animation.png");
    tex2 = new TextureAtlas(Gdx.files.internal("data/pack"));
    font2 = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
    // tex3 = new Texture("data/test.etc1");
    // map = TiledLoader.createMap(Gdx.files.internal("data/tiledmap/tilemap csv.tmx"));
    // atlas = new TileAtlas(map, Gdx.files.internal("data/tiledmap/"));
    // renderer = new TileMapRenderer(map, atlas, 8, 8);
    shader = new ShaderProgram(Gdx.files.internal("data/g2d/batchCommon.vert").readString(), Gdx.files.internal("data/g2d/monochrome.frag").readString());
    System.out.println("plain took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
    start = TimeUtils.nanoTime();
    manager.load("data/animation.png", Texture.class);
    // manager.load("data/pack1.png", Texture.class);
    manager.load("data/pack", TextureAtlas.class);
    // manager.load("data/verdana39.png", Texture.class);
    manager.load("data/verdana39.fnt", BitmapFont.class);
    // manager.load("data/multipagefont.fnt", BitmapFont.class);
    // manager.load("data/test.etc1", Texture.class);
    // manager.load("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class, new
    // TileMapRendererLoader.TileMapParameter("data/tiledmap/", 8, 8));
    manager.load("data/i18n/message2", I18NBundle.class, new I18NBundleLoader.I18NBundleParameter(reloads % 2 == 0 ? Locale.ITALIAN : Locale.ENGLISH));
    manager.load("data/g2d/monochrome.frag", ShaderProgram.class, new ShaderProgramLoader.ShaderProgramParameter() {

        {
            vertexFile = "data/g2d/batchCommon.vert";
        }
    });
}
Also used : I18NBundleLoader(com.badlogic.gdx.assets.loaders.I18NBundleLoader) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ShaderProgramLoader(com.badlogic.gdx.assets.loaders.ShaderProgramLoader) Texture(com.badlogic.gdx.graphics.Texture)

Example 7 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class TextureAtlasTest method create.

public void create() {
    batch = new SpriteBatch();
    renderer = new ShapeRenderer();
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
    jumpAtlas = new TextureAtlas(Gdx.files.internal("data/jump.txt"));
    jumpAnimation = new Animation(0.25f, jumpAtlas.findRegions("ALIEN_JUMP_"));
    badlogic = atlas.createSprite("badlogicslice");
    badlogic.setPosition(50, 50);
    // badlogicSmall = atlas.createSprite("badlogicsmall");
    badlogicSmall = atlas.createSprite("badlogicsmall-rotated");
    badlogicSmall.setPosition(10, 10);
    AtlasRegion region = atlas.findRegion("badlogicsmall");
    System.out.println("badlogicSmall original size: " + region.originalWidth + ", " + region.originalHeight);
    System.out.println("badlogicSmall packed size: " + region.packedWidth + ", " + region.packedHeight);
    star = atlas.createSprite("particle-star");
    star.setPosition(10, 70);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), atlas.findRegion("font"), false);
    Gdx.gl.glClearColor(0, 1, 0, 1);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyUp(int keycode) {
            if (keycode == Keys.UP) {
                badlogicSmall.flip(false, true);
            } else if (keycode == Keys.RIGHT) {
                badlogicSmall.flip(true, false);
            } else if (keycode == Keys.LEFT) {
                badlogicSmall.setSize(512, 512);
            } else if (keycode == Keys.DOWN) {
                badlogicSmall.rotate90(true);
            }
            return super.keyUp(keycode);
        }
    });
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) Animation(com.badlogic.gdx.graphics.g2d.Animation) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 8 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class TextureRegion3DTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
    atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
    regions = atlas.getRegions();
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
    model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    instance = new ModelInstance(model);
    attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 9 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class GwtTest method create.

@Override
public void create() {
    Preferences pref = Gdx.app.getPreferences("test");
    boolean resultb = pref.getBoolean("test");
    int resulti = pref.getInteger("test");
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
    if (!shader.isCompiled())
        throw new GdxRuntimeException(shader.getLog());
    mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
    texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    String params = Gdx.files.internal("data/gwttestparams.txt").readString();
    numSprites = Integer.parseInt(params);
    batch = new SpriteBatch();
    positions = new ArrayList<Vector2>();
    for (int i = 0; i < numSprites; i++) {
        positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
    }
    sprite = new Sprite(texture);
    sprite.setSize(64, 64);
    sprite.setOrigin(32, 32);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    cache = font.newFontCache();
    cache.setColor(Color.RED);
    cache.setText("This is a Test", 0, 0);
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Vector2(com.badlogic.gdx.math.Vector2) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Preferences(com.badlogic.gdx.Preferences) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 10 with TextureAtlas

use of com.badlogic.gdx.graphics.g2d.TextureAtlas in project libgdx by libgdx.

the class APKExpansionTest method create.

@Override
public void create() {
    if ((((AndroidFiles) Gdx.files)).setAPKExpansion(1, 0)) {
        resolver = new ZipFileHandleResolver();
    } else {
        Gdx.app.error("libgdx", "No Expansion can be opened");
    }
    assetManager = new AssetManager();
    FileHandleResolver resolver = new InternalFileHandleResolver();
    assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
    assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
    loadFont(assetManager, "data/DroidSerif-Regular.ttf", 12);
    loadFont(assetManager, "data/" + extensionPrefix + "DroidSerif-Regular.ttf", 12);
    assetManager.load("data/" + extensionPrefix + "testpackobb", TextureAtlas.class);
    assetManager.finishLoading();
    sound = Gdx.audio.newSound(Gdx.files.internal("data/" + extensionPrefix + "chirp.ogg"));
    sound.play();
    texture = new Texture(resolver.resolve("data/" + extensionPrefix + "badlogic.jpg"));
    batch = new SpriteBatch();
    TextureAtlas atlas = assetManager.get("data/" + extensionPrefix + "testpackobb");
    atlasTextureRegion = new TextureRegion(atlas.findRegion("water"));
    sound = Gdx.audio.newSound(Gdx.files.internal("data/shotgun.ogg"));
    sound.play();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) FreeTypeFontGeneratorLoader(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader) FreetypeFontLoader(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)33 Texture (com.badlogic.gdx.graphics.Texture)11 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)11 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)10 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)7 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 FileHandle (com.badlogic.gdx.files.FileHandle)5 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)4 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 Array (com.badlogic.gdx.utils.Array)4 Animation (com.badlogic.gdx.graphics.g2d.Animation)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)3 TexturePacker (com.badlogic.gdx.tools.texturepacker.TexturePacker)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Page (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Page)2 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2