Search in sources :

Example 31 with TextureRegion

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

the class EdgeDetectionTest method create.

public void create() {
    ShaderProgram.pedantic = false;
    /*
		 * shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
		 * "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
		 * "couldn't compile scene shader: " + shader.getLog()); }
		 */
    batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
    if (!batchShader.isCompiled()) {
        Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
    }
    ObjLoader objLoader = new ObjLoader();
    scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    sceneInstance = new ModelInstance(scene);
    modelBatch = new ModelBatch();
    fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0, 0, 10);
    cam.lookAt(0, 0, 0);
    cam.far = 30;
    batch = new SpriteBatch();
    batch.setShader(batchShader);
    fboRegion = new TextureRegion(fbo.getColorBufferTexture());
    fboRegion.flip(false, true);
    logger = new FPSLogger();
    calculateOffsets();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) ObjLoader(com.badlogic.gdx.graphics.g3d.loader.ObjLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) FPSLogger(com.badlogic.gdx.graphics.FPSLogger)

Example 32 with TextureRegion

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

the class Box2DTest method create.

@Override
public void create() {
    // setup the camera. In Box2D we operate on a
    // meter scale, pixels won't do it. So we use
    // an orthographic camera with a viewport of
    // 48 meters in width and 32 meters in height.
    // We also position the camera so that it
    // looks at (0,16) (that's where the middle of the
    // screen will be located).
    camera = new OrthographicCamera(48, 32);
    camera.position.set(0, 16, 0);
    // next we setup the immediate mode renderer
    renderer = new ShapeRenderer();
    // next we create the box2d debug renderer
    debugRenderer = new Box2DDebugRenderer();
    // next we create a SpriteBatch and a font
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    font.setColor(Color.RED);
    textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
    // next we create out physics world.
    createPhysicsWorld();
    // register ourselfs as an InputProcessor
    Gdx.input.setInputProcessor(this);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 33 with TextureRegion

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

the class AnimationTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/walkanim.png"));
    TextureRegion[] leftWalkFrames = TextureRegion.split(texture, 64, 64)[0];
    TextureRegion[] rightWalkFrames = new TextureRegion[leftWalkFrames.length];
    for (int i = 0; i < rightWalkFrames.length; i++) {
        TextureRegion frame = new TextureRegion(leftWalkFrames[i]);
        frame.flip(true, false);
        rightWalkFrames[i] = frame;
    }
    leftWalk = new Animation<TextureRegion>(0.25f, leftWalkFrames);
    rightWalk = new Animation<TextureRegion>(0.25f, rightWalkFrames);
    cavemen = new Caveman[100];
    for (int i = 0; i < 100; i++) {
        cavemen[i] = new Caveman((float) Math.random() * Gdx.graphics.getWidth(), (float) Math.random() * Gdx.graphics.getHeight(), Math.random() > 0.5 ? true : false);
    }
    batch = new SpriteBatch();
    fpsLog = new FPSLogger();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) FPSLogger(com.badlogic.gdx.graphics.FPSLogger)

Example 34 with TextureRegion

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

the class TiledMapBench method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 320, 320);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    {
        tiles = new Texture(Gdx.files.internal("data/maps/tiled/tiles.png"));
        TextureRegion[][] splitTiles = TextureRegion.split(tiles, 32, 32);
        map = new TiledMap();
        MapLayers layers = map.getLayers();
        for (int l = 0; l < 20; l++) {
            TiledMapTileLayer layer = new TiledMapTileLayer(150, 100, 32, 32);
            for (int x = 0; x < 150; x++) {
                for (int y = 0; y < 100; y++) {
                    int ty = (int) (Math.random() * splitTiles.length);
                    int tx = (int) (Math.random() * splitTiles[ty].length);
                    Cell cell = new Cell();
                    cell.setTile(new StaticTiledMapTile(splitTiles[ty][tx]));
                    layer.setCell(x, y, cell);
                }
            }
            layers.add(layer);
        }
    }
    renderer = new OrthogonalTiledMapRenderer(map);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Cell(com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell) MapLayers(com.badlogic.gdx.maps.MapLayers)

Example 35 with TextureRegion

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

the class TiledMapObjectLoadingTest method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    shapeRenderer.setColor(Color.BLUE);
    Gdx.gl20.glLineWidth(2);
    MapLayer layer = map.getLayers().get("Objects");
    AnimatedTiledMapTile.updateAnimationBaseTime();
    for (MapObject mapObject : layer.getObjects()) {
        if (mapObject instanceof TiledMapTileMapObject) {
            batch.begin();
            TiledMapTileMapObject tmtObject = (TiledMapTileMapObject) mapObject;
            TextureRegion textureRegion = tmtObject.getTile().getTextureRegion();
            // TilEd rotation is clockwise, we need counter-clockwise.
            float rotation = -tmtObject.getRotation();
            float scaleX = tmtObject.getScaleX();
            float scaleY = tmtObject.getScaleY();
            float xPos = tmtObject.getX();
            float yPos = tmtObject.getY();
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.draw(textureRegion, xPos, yPos, tmtObject.getOriginX() * scaleX, tmtObject.getOriginY() * scaleY, textureRegion.getRegionWidth() * scaleX, textureRegion.getRegionHeight() * scaleY, 1f, 1f, rotation);
            // We flip back to the original state.
            textureRegion.flip(tmtObject.isFlipHorizontally(), tmtObject.isFlipVertically());
            batch.end();
        } else if (mapObject instanceof EllipseMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
            shapeRenderer.ellipse(ellipse.x, ellipse.y, ellipse.width, ellipse.height);
            shapeRenderer.end();
        } else if (mapObject instanceof RectangleMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
            shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
            shapeRenderer.end();
        } else if (mapObject instanceof PolygonMapObject) {
            shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
            Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
            shapeRenderer.polygon(polygon.getTransformedVertices());
            shapeRenderer.end();
        }
    }
    batch.begin();
    font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
    batch.end();
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject) Ellipse(com.badlogic.gdx.math.Ellipse) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) MapLayer(com.badlogic.gdx.maps.MapLayer) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) Rectangle(com.badlogic.gdx.math.Rectangle) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) Polygon(com.badlogic.gdx.math.Polygon) MapObject(com.badlogic.gdx.maps.MapObject) TextureMapObject(com.badlogic.gdx.maps.objects.TextureMapObject) EllipseMapObject(com.badlogic.gdx.maps.objects.EllipseMapObject) TiledMapTileMapObject(com.badlogic.gdx.maps.tiled.objects.TiledMapTileMapObject) RectangleMapObject(com.badlogic.gdx.maps.objects.RectangleMapObject) PolygonMapObject(com.badlogic.gdx.maps.objects.PolygonMapObject)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)115 Texture (com.badlogic.gdx.graphics.Texture)57 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)22 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)18 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)13 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)13 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)11 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)11 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)10 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)10 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)10 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Color (com.badlogic.gdx.graphics.Color)7 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)7 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)7 Test (org.junit.Test)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)6