Search in sources :

Example 36 with Texture

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

the class DecalTest method create.

@Override
public void create() {
    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthFunc(GL20.GL_LESS);
    egg = new Texture(Gdx.files.internal("data/egg.png"));
    egg.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    egg.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    wheel = new Texture(Gdx.files.internal("data/wheel.png"));
    wheel.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    wheel.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    w = Gdx.graphics.getWidth() / 0.8f;
    h = Gdx.graphics.getHeight() / 0.8f;
    for (int i = 0; i < INITIAL_RENDERED; i++) {
        toRender.add(makeDecal());
    }
    cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 10f;
    cam.position.set(0, 0, 0.1f);
    cam.direction.set(0, 0, -1f);
    batch = new DecalBatch(new CameraGroupStrategy(cam));
    Gdx.gl.glClearColor(1, 1, 0, 1);
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) CameraGroupStrategy(com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy) Texture(com.badlogic.gdx.graphics.Texture)

Example 37 with Texture

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

the class DownloadTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    HttpRequest request = new HttpRequest(HttpMethods.GET);
    request.setUrl("https://www.google.at/images/srpr/logo11w.png");
    Gdx.net.sendHttpRequest(request, new HttpResponseListener() {

        @Override
        public void handleHttpResponse(HttpResponse httpResponse) {
            final byte[] bytes = httpResponse.getResult();
            Gdx.app.postRunnable(new Runnable() {

                @Override
                public void run() {
                    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
                    texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), false, false, true));
                }
            });
        }

        @Override
        public void failed(Throwable t) {
            t.printStackTrace();
            Gdx.app.log("EmptyDownloadTest", "Failed", t);
        }

        @Override
        public void cancelled() {
            Gdx.app.log("EmptyDownloadTest", "Cancelled");
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) HttpResponse(com.badlogic.gdx.Net.HttpResponse) PixmapTextureData(com.badlogic.gdx.graphics.glutils.PixmapTextureData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener)

Example 38 with Texture

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

the class DragAndDropTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    final Skin skin = new Skin();
    skin.add("default", new LabelStyle(new BitmapFont(), Color.WHITE));
    skin.add("badlogic", new Texture("data/badlogic.jpg"));
    Image sourceImage = new Image(skin, "badlogic");
    sourceImage.setBounds(50, 125, 100, 100);
    stage.addActor(sourceImage);
    Image validTargetImage = new Image(skin, "badlogic");
    validTargetImage.setBounds(200, 50, 100, 100);
    stage.addActor(validTargetImage);
    Image invalidTargetImage = new Image(skin, "badlogic");
    invalidTargetImage.setBounds(200, 200, 100, 100);
    stage.addActor(invalidTargetImage);
    DragAndDrop dragAndDrop = new DragAndDrop();
    dragAndDrop.addSource(new Source(sourceImage) {

        public Payload dragStart(InputEvent event, float x, float y, int pointer) {
            Payload payload = new Payload();
            payload.setObject("Some payload!");
            payload.setDragActor(new Label("Some payload!", skin));
            Label validLabel = new Label("Some payload!", skin);
            validLabel.setColor(0, 1, 0, 1);
            payload.setValidDragActor(validLabel);
            Label invalidLabel = new Label("Some payload!", skin);
            invalidLabel.setColor(1, 0, 0, 1);
            payload.setInvalidDragActor(invalidLabel);
            return payload;
        }
    });
    dragAndDrop.addTarget(new Target(validTargetImage) {

        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            getActor().setColor(Color.GREEN);
            return true;
        }

        public void reset(Source source, Payload payload) {
            getActor().setColor(Color.WHITE);
        }

        public void drop(Source source, Payload payload, float x, float y, int pointer) {
            System.out.println("Accepted: " + payload.getObject() + " " + x + ", " + y);
        }
    });
    dragAndDrop.addTarget(new Target(invalidTargetImage) {

        public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
            getActor().setColor(Color.RED);
            return false;
        }

        public void reset(Source source, Payload payload) {
            getActor().setColor(Color.WHITE);
        }

        public void drop(Source source, Payload payload, float x, float y, int pointer) {
        }
    });
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) Source(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Source) Target(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Target) DragAndDrop(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Payload(com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop.Payload) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 39 with Texture

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

the class ETC1Test method create.

@Override
public void create() {
    font = new BitmapFont();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    controller = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(controller);
    Pixmap pixmap = new Pixmap(32, 32, Format.RGB565);
    pixmap.setColor(1, 0, 0, 1);
    pixmap.fill();
    pixmap.setColor(0, 1, 0, 1);
    pixmap.drawLine(0, 0, 32, 32);
    pixmap.drawLine(0, 32, 32, 0);
    ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap);
    pixmap.dispose();
    pixmap = ETC1.decodeImage(encodedImage, Format.RGB565);
    encodedImage.dispose();
    img1 = new Texture(pixmap);
    img2 = new Texture("data/test.etc1");
    batch = new SpriteBatch();
    pixmap.dispose();
}
Also used : ETC1Data(com.badlogic.gdx.graphics.glutils.ETC1.ETC1Data) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 40 with Texture

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

the class FilterPerformanceTest method create.

public void create() {
    batch = new SpriteBatch();
    sceneMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    textMatrix = new Matrix4().setToOrtho2D(0, 0, 480, 320);
    atlas = new TextureAtlas(Gdx.files.internal("data/issue_pack"), Gdx.files.internal("data/"));
    texture = new Texture(Gdx.files.internal("data/resource1.jpg"), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
    setTextureFilter(0);
    setModeString();
    sprite = atlas.createSprite("map");
    sprite2 = new Sprite(texture, 0, 0, 855, 480);
    font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean touchDown(int x, int y, int pointer, int newParam) {
            mode++;
            if (mode == filters.length * 2)
                mode = 0;
            setTextureFilter(mode / 2);
            setModeString();
            return false;
        }
    });
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) InputAdapter(com.badlogic.gdx.InputAdapter) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

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