Search in sources :

Example 61 with Texture

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

the class TextureDataTest method create.

public void create() {
    spriteBatch = new SpriteBatch();
    // texture = new Texture(new PixmapTextureData(new Pixmap(Gdx.files.internal("data/t8890.png")), null, false, true));
    texture = new Texture(new FileTextureData(Gdx.files.internal("data/t8890.png"), null, null, false));
}
Also used : FileTextureData(com.badlogic.gdx.graphics.glutils.FileTextureData) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 62 with Texture

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

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

the class VertexBufferObjectShaderTest method create.

@Override
public void create() {
    //@off
    String vertexShader = "attribute vec4 a_position;    \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main()                  \n" + "{                            \n" + "   v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n" + "   v_texCoords = a_texCoords; \n" + "   gl_Position =  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" + "}";
    //@on
    shader = new ShaderProgram(vertexShader, fragmentShader);
    vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_color"));
    float[] vertices = new float[] { -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f) };
    vbo.setVertices(vertices, 0, vertices.length);
    indices = new IndexBufferObject(3);
    indices.setIndices(new short[] { 0, 1, 2 }, 0, 3);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) IndexBufferObject(com.badlogic.gdx.graphics.glutils.IndexBufferObject) VertexBufferObject(com.badlogic.gdx.graphics.glutils.VertexBufferObject) Texture(com.badlogic.gdx.graphics.Texture)

Example 64 with Texture

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

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

the class SpriteCacheOffsetTest method create.

public void create() {
    texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    Sprite sprite = new Sprite(texture);
    sprite.setSize(tileSize, tileSize);
    cache = new SpriteCache(1000, false);
    for (int y = 0; y < tileMapHeight; y++) {
        cache.beginCache();
        for (int x = 0; x < tileMapWidth; x++) {
            sprite.setPosition(x * tileSize, y * tileSize);
            cache.add(sprite);
        }
        cache.endCache();
        sprite.rotate90(true);
    }
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) SpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)235 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)78 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)62 Pixmap (com.badlogic.gdx.graphics.Pixmap)56 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)35 Stage (com.badlogic.gdx.scenes.scene2d.Stage)35 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)26 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)21 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)17 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)16 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)16 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)14 Material (com.badlogic.gdx.graphics.g3d.Material)12 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)12 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)11 FileHandle (com.badlogic.gdx.files.FileHandle)10