Search in sources :

Example 26 with Texture

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

the class FrameBufferTest method create.

@Override
public void create() {
    mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
    float c1 = Color.toFloatBits(255, 0, 0, 255);
    float c2 = Color.toFloatBits(255, 0, 0, 255);
    float c3 = Color.toFloatBits(0, 0, 255, 255);
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1 });
    stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
    stencilMesh.setVertices(new float[] { -0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1 });
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    spriteBatch = new SpriteBatch();
    frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false);
    stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true);
    createShader(Gdx.graphics);
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 27 with Texture

use of com.badlogic.gdx.graphics.Texture 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 28 with Texture

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

the class CharacterTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
    // Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, null));
    character = world.add("capsule", 5f, 3f, 5f);
    // Set by reference
    characterTransform = character.transform;
    characterTransform.rotate(Vector3.X, 90);
    // Create the physics representation of the character
    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(characterTransform);
    ghostShape = new btCapsuleShape(2f, 2f);
    ghostObject.setCollisionShape(ghostShape);
    ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
    characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f, Vector3.Y);
    // And add it to the physics world
    world.collisionWorld.addCollisionObject(ghostObject, (short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter, (short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
    ((btDiscreteDynamicsWorld) (world.collisionWorld)).addAction(characterController);
    // Add the ground
    (ground = world.add("ground", 0f, 0f, 0f)).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    // Create some boxes to play with
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            }
        }
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btCapsuleShape(com.badlogic.gdx.physics.bullet.collision.btCapsuleShape) Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController(com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController)

Example 29 with Texture

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

the class TileTest method create.

@Override
public void create() {
    cam = new OrthographicCamera(480, 320);
    cam.position.set(WIDTH * 32 / 2, HEIGHT * 32 / 2, 0);
    camController = new OrthoCamController(cam);
    Gdx.input.setInputProcessor(camController);
    texture = new Texture(Gdx.files.internal("data/tiles.png"));
    Random rand = new Random();
    for (int i = 0; i < LAYERS; i++) {
        caches[i] = new SpriteCache();
        SpriteCache cache = caches[i];
        cache.beginCache();
        for (int y = 0; y < HEIGHT; y++) {
            for (int x = 0; x < WIDTH; x++) {
                int tileX = rand.nextInt(5);
                int tileY = rand.nextInt(5);
                cache.add(texture, x << 5, y << 5, 1 + tileX * 33, 1 + tileY * 33, 32, 32);
            }
        }
        layers[i] = cache.endCache();
    }
}
Also used : Random(java.util.Random) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture)

Example 30 with Texture

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

the class OcclusionBuffer method drawDebugTexture.

/** Draw the depth buffer to a texture. Slow, should only be used for debugging purposes.
	 *
	 * @return Region of debug texture */
public TextureRegion drawDebugTexture() {
    if (debugPixmap == null) {
        debugPixmap = new Pixmap(bufferWidth, bufferHeight, Pixmap.Format.RGBA8888);
        debugTexture = new Texture(debugPixmap);
        debugTextureRegion = new TextureRegion(debugTexture);
        debugTextureRegion.flip(false, true);
    }
    debugPixmap.setColor(Color.BLACK);
    debugPixmap.fill();
    // Find min/max depth values in buffer
    float minDepth = Float.POSITIVE_INFINITY;
    float maxDepth = Float.NEGATIVE_INFINITY;
    buffer.clear();
    while (buffer.position() < buffer.capacity()) {
        float depth = MathUtils.clamp(buffer.get(), 0, Float.POSITIVE_INFINITY);
        minDepth = Math.min(depth, minDepth);
        maxDepth = Math.max(depth, maxDepth);
    }
    float extent = 1 / (maxDepth - minDepth);
    buffer.clear();
    // Draw to pixmap
    for (int x = 0; x < bufferWidth; x++) {
        for (int y = 0; y < bufferHeight; y++) {
            float depth = MathUtils.clamp(buffer.get(x + y * bufferWidth), 0, Float.POSITIVE_INFINITY);
            float c = depth * extent;
            debugPixmap.drawPixel(x, y, Color.rgba8888(c, c, c, 1));
        }
    }
    debugTexture.draw(debugPixmap, 0, 0);
    return debugTextureRegion;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

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