Search in sources :

Example 26 with SpriteBatch

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

the class TideMapDirectLoaderTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, (w / h) * 10, 10);
    camera.update();
    cameraController = new OrthoCamController(camera);
    Gdx.input.setInputProcessor(cameraController);
    font = new BitmapFont();
    batch = new SpriteBatch();
    map = new TideMapLoader().load("data/maps/tide/Map01.tide");
    renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
}
Also used : OrthogonalTiledMapRenderer(com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) OrthoCamController(com.badlogic.gdx.tests.utils.OrthoCamController) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) TideMapLoader(com.badlogic.gdx.maps.tiled.TideMapLoader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 27 with SpriteBatch

use of com.badlogic.gdx.graphics.g2d.SpriteBatch 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, 15, 0);
    // create the debug renderer
    renderer = new Box2DDebugRenderer();
    // create the world
    world = new World(new Vector2(0, -10), true);
    // we also need an invisible zero size ground body
    // to which we can connect the mouse joint
    BodyDef bodyDef = new BodyDef();
    groundBody = world.createBody(bodyDef);
    // call abstract method to populate the world
    createWorld(world);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 28 with SpriteBatch

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

the class VBOWithVAOPerformanceTest method create.

@Override
public void create() {
    if (Gdx.gl30 == null) {
        throw new GdxRuntimeException("GLES 3.0 profile required for this test");
    }
    String vertexShader = "attribute vec4 a_position;    \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main()                  \n" + "{                            \n" + "   v_color = a_color; \n" + "   v_texCoords = a_texCoord0; \n" + "   gl_Position =  u_worldView * a_position;  \n" + "}                            \n";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main()                                  \n" + "{                                            \n" + "  gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
    shader = new ShaderProgram(vertexShader, fragmentShader);
    if (shader.isCompiled() == false) {
        Gdx.app.log("ShaderTest", shader.getLog());
        Gdx.app.exit();
    }
    int numSprites = 1000;
    int maxIndices = numSprites * 6;
    int maxVertices = numSprites * 6;
    VertexAttribute[] vertexAttributes = new VertexAttribute[] { VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0) };
    VertexBufferObjectWithVAO newVBOWithVAO = new VertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
    OldVertexBufferObjectWithVAO oldVBOWithVAO = new OldVertexBufferObjectWithVAO(false, maxVertices, vertexAttributes);
    IndexBufferObjectSubData newIndices = new IndexBufferObjectSubData(false, maxIndices);
    IndexBufferObjectSubData oldIndices = new IndexBufferObjectSubData(false, maxIndices);
    newVBOWithVAOMesh = new Mesh(newVBOWithVAO, newIndices, false) {
    };
    oldVBOWithVAOMesh = new Mesh(oldVBOWithVAO, oldIndices, false) {
    };
    float[] vertexArray = new float[maxVertices * 9];
    int index = 0;
    int stride = 9 * 6;
    for (int i = 0; i < numSprites; i++) {
        addRandomSprite(vertexArray, index);
        index += stride;
    }
    short[] indexArray = new short[maxIndices];
    for (short i = 0; i < maxIndices; i++) {
        indexArray[i] = i;
    }
    newVBOWithVAOMesh.setVertices(vertexArray);
    newVBOWithVAOMesh.setIndices(indexArray);
    oldVBOWithVAOMesh.setVertices(vertexArray);
    oldVBOWithVAOMesh.setIndices(indexArray);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    batch = new SpriteBatch();
    bitmapFont = new BitmapFont();
    stringBuilder = new StringBuilder();
}
Also used : IndexBufferObjectSubData(com.badlogic.gdx.graphics.glutils.IndexBufferObjectSubData) StringBuilder(com.badlogic.gdx.utils.StringBuilder) 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) VertexBufferObjectWithVAO(com.badlogic.gdx.graphics.glutils.VertexBufferObjectWithVAO) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 29 with SpriteBatch

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

the class SpriteBatchTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch(1000);
    Pixmap pixmap = new Pixmap(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture = new Texture(32, 32, Format.RGB565);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    texture.draw(pixmap, 0, 0);
    pixmap.dispose();
    pixmap = new Pixmap(32, 32, Format.RGBA8888);
    pixmap.setColor(1, 1, 0, 0.5f);
    pixmap.fill();
    texture2 = new Texture(pixmap);
    pixmap.dispose();
    for (int i = 0; i < sprites.length; i += 6) {
        sprites[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites[i + 2] = 0;
        sprites[i + 3] = 0;
        sprites[i + 4] = 32;
        sprites[i + 5] = 32;
        sprites2[i] = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        sprites2[i + 1] = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        sprites2[i + 2] = 0;
        sprites2[i + 3] = 0;
        sprites2[i + 4] = 32;
        sprites2[i + 5] = 32;
    }
    for (int i = 0; i < SPRITES * 2; i++) {
        int x = (int) (Math.random() * (Gdx.graphics.getWidth() - 32));
        int y = (int) (Math.random() * (Gdx.graphics.getHeight() - 32));
        if (i >= SPRITES)
            sprites3[i] = new Sprite(texture2, 32, 32);
        else
            sprites3[i] = new Sprite(texture, 32, 32);
        sprites3[i].setPosition(x, y);
        sprites3[i].setOrigin(16, 16);
    }
    Gdx.input.setInputProcessor(this);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 30 with SpriteBatch

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

the class MoveSpriteExample method create.

public void create() {
    // create a SpriteBatch with which to render the sprite
    batch = new SpriteBatch();
    // load the sprite's texture. note: usually you have more than
    // one sprite in a texture, see {@see TextureAtlas} and {@see TextureRegion}.
    texture = new Texture(Gdx.files.internal("data/bobargb8888-32x32.png"));
    // create an {@link OrthographicCamera} which is used to transform
    // touch coordinates to world coordinates.
    camera = new OrthographicCamera();
    // we want the camera to setup a viewport with pixels as units, with the
    // y-axis pointing upwards. The origin will be in the lower left corner
    // of the screen.
    camera.setToOrtho(false);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)121 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)64 Texture (com.badlogic.gdx.graphics.Texture)59 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)32 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)22 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)16 Pixmap (com.badlogic.gdx.graphics.Pixmap)15 AssetManager (com.badlogic.gdx.assets.AssetManager)13 Stage (com.badlogic.gdx.scenes.scene2d.Stage)13 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)11 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)10 InputAdapter (com.badlogic.gdx.InputAdapter)9 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)8 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)7 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)7 Vector2 (com.badlogic.gdx.math.Vector2)7