Search in sources :

Example 16 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class StageTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    stage = new Stage(new ScreenViewport());
    float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
    for (int i = 0; i < NUM_GROUPS; i++) {
        Group group = new Group();
        group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
        group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
        group.setOrigin(loc, loc);
        fillGroup(group, texture);
        stage.addActor(group);
    }
    uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
    uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    ui = new Stage(new ScreenViewport());
    Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
    blend.setAlign(Align.center);
    blend.setScaling(Scaling.none);
    blend.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (stage.getBatch().isBlendingEnabled())
                stage.getBatch().disableBlending();
            else
                stage.getBatch().enableBlending();
            return true;
        }
    });
    blend.setY(ui.getHeight() - 64);
    Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
    rotate.setAlign(Align.center);
    rotate.setScaling(Scaling.none);
    rotate.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            rotateSprites = !rotateSprites;
            return true;
        }
    });
    rotate.setPosition(64, blend.getY());
    Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
    scale.setAlign(Align.center);
    scale.setScaling(Scaling.none);
    scale.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            scaleSprites = !scaleSprites;
            return true;
        }
    });
    scale.setPosition(128, blend.getY());
    {
        Actor shapeActor = new Actor() {

            public void drawDebug(ShapeRenderer shapes) {
                shapes.set(ShapeType.Filled);
                shapes.setColor(getColor());
                shapes.rect(getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
            }
        };
        shapeActor.setBounds(0, 0, 100, 150);
        shapeActor.setOrigin(50, 75);
        shapeActor.debug();
        sprites.add(shapeActor);
        Group shapeGroup = new Group();
        shapeGroup.setBounds(300, 300, 300, 300);
        shapeGroup.setOrigin(50, 75);
        shapeGroup.setTouchable(Touchable.childrenOnly);
        shapeGroup.addActor(shapeActor);
        stage.addActor(shapeGroup);
    }
    ui.addActor(blend);
    ui.addActor(rotate);
    ui.addActor(scale);
    fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
    fps.setPosition(10, 30);
    fps.setColor(0, 1, 0, 1);
    ui.addActor(fps);
    renderer = new ShapeRenderer();
    Gdx.input.setInputProcessor(this);
}
Also used : Group(com.badlogic.gdx.scenes.scene2d.Group) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 17 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class PixelPerfectTest method create.

@Override
public void create() {
    Pixmap pixmap = new Pixmap(16, 16, Pixmap.Format.RGBA8888);
    pixmap.setColor(Color.BLUE);
    pixmap.fill();
    pixmap.setColor(Color.RED);
    pixmap.drawLine(0, 0, 15, 15);
    pixmap.drawLine(0, 15, 15, 0);
    tex = new Texture(pixmap);
    batch = new SpriteBatch();
    cam = new OrthographicCamera();
    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 18 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class PixelsPerInchTest method create.

@Override
public void create() {
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    batch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 19 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class MipMapTest method create.

@Override
public void create() {
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(0, 1.5f, 1.5f);
    camera.lookAt(0, 0, 0);
    camera.update();
    controller = new PerspectiveCamController(camera);
    mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
    mesh.setVertices(new float[] { -1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0 });
    mesh.setIndices(new short[] { 0, 1, 2, 3 });
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal("data/shaders/flattex-frag.glsl").readString());
    if (!shader.isCompiled())
        throw new GdxRuntimeException("shader error: " + shader.getLog());
    textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
    MipMapGenerator.setUseHardwareMipMap(false);
    textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
    currTexture = textureHW;
    createUI();
    multiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(multiplexer);
    multiplexer.addProcessor(ui);
    multiplexer.addProcessor(controller);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) PerspectiveCamController(com.badlogic.gdx.tests.utils.PerspectiveCamController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Texture(com.badlogic.gdx.graphics.Texture)

Example 20 with Texture

use of com.badlogic.gdx.graphics.Texture in project libgdx by libgdx.

the class MusicTest method create.

@Override
public void create() {
    music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
    music.play();
    buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png")));
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    slider = new Slider(0, 100, 0.1f, false, skin);
    slider.setPosition(200, 20);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (!sliderUpdating && slider.isDragging())
                music.setPosition((slider.getValue() / 100f) * songDuration);
        }
    });
    stage.addActor(slider);
    Gdx.input.setInputProcessor(stage);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)162 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)59 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)31 Pixmap (com.badlogic.gdx.graphics.Pixmap)27 Stage (com.badlogic.gdx.scenes.scene2d.Stage)23 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)17 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)14 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)11 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)11 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)11 Material (com.badlogic.gdx.graphics.g3d.Material)10 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)10 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)8 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)8 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)8 Actor (com.badlogic.gdx.scenes.scene2d.Actor)8 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)8