Search in sources :

Example 11 with Mesh

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

the class Shapes method genCube.

public static Mesh genCube() {
    Mesh mesh = new Mesh(true, 24, 36, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texcoords"));
    float[] cubeVerts = { -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f };
    float[] cubeNormals = { 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f };
    float[] cubeTex = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f };
    float[] vertices = new float[24 * 8];
    int pIdx = 0;
    int nIdx = 0;
    int tIdx = 0;
    for (int i = 0; i < vertices.length; ) {
        vertices[i++] = cubeVerts[pIdx++];
        vertices[i++] = cubeVerts[pIdx++];
        vertices[i++] = cubeVerts[pIdx++];
        vertices[i++] = cubeNormals[nIdx++];
        vertices[i++] = cubeNormals[nIdx++];
        vertices[i++] = cubeNormals[nIdx++];
        vertices[i++] = cubeTex[tIdx++];
        vertices[i++] = cubeTex[tIdx++];
    }
    short[] indices = { 0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 15, 14, 12, 14, 13, 16, 17, 18, 16, 18, 19, 20, 23, 22, 20, 22, 21 };
    mesh.setVertices(vertices);
    mesh.setIndices(indices);
    return mesh;
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh)

Example 12 with Mesh

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

the class GwtTest method create.

@Override
public void create() {
    Preferences pref = Gdx.app.getPreferences("test");
    boolean resultb = pref.getBoolean("test");
    int resulti = pref.getInteger("test");
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
    if (!shader.isCompiled())
        throw new GdxRuntimeException(shader.getLog());
    mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
    texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    String params = Gdx.files.internal("data/gwttestparams.txt").readString();
    numSprites = Integer.parseInt(params);
    batch = new SpriteBatch();
    positions = new ArrayList<Vector2>();
    for (int i = 0; i < numSprites; i++) {
        positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
    }
    sprite = new Sprite(texture);
    sprite.setSize(64, 64);
    sprite.setOrigin(32, 32);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    cache = font.newFontCache();
    cache.setColor(Color.RED);
    cache.setText("This is a Test", 0, 0);
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) 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) Vector2(com.badlogic.gdx.math.Vector2) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Preferences(com.badlogic.gdx.Preferences) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 13 with Mesh

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

the class Model method convertMesh.

protected void convertMesh(ModelMesh modelMesh) {
    int numIndices = 0;
    for (ModelMeshPart part : modelMesh.parts) {
        numIndices += part.indices.length;
    }
    VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
    int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);
    Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
    meshes.add(mesh);
    disposables.add(mesh);
    BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
    int offset = 0;
    mesh.getIndicesBuffer().clear();
    for (ModelMeshPart part : modelMesh.parts) {
        MeshPart meshPart = new MeshPart();
        meshPart.id = part.id;
        meshPart.primitiveType = part.primitiveType;
        meshPart.offset = offset;
        meshPart.size = part.indices.length;
        meshPart.mesh = mesh;
        mesh.getIndicesBuffer().put(part.indices);
        offset += meshPart.size;
        meshParts.add(meshPart);
    }
    mesh.getIndicesBuffer().position(0);
    for (MeshPart part : meshParts) part.update();
}
Also used : ModelMeshPart(com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart) VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) ModelMesh(com.badlogic.gdx.graphics.g3d.model.data.ModelMesh) Mesh(com.badlogic.gdx.graphics.Mesh) ModelMeshPart(com.badlogic.gdx.graphics.g3d.model.data.ModelMeshPart) MeshPart(com.badlogic.gdx.graphics.g3d.model.MeshPart)

Example 14 with Mesh

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

the class BillboardParticleBatch method allocRenderable.

protected Renderable allocRenderable() {
    Renderable renderable = new Renderable();
    renderable.meshPart.primitiveType = GL20.GL_TRIANGLES;
    renderable.meshPart.offset = 0;
    renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture));
    renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes);
    renderable.meshPart.mesh.setIndices(indices);
    renderable.shader = shader;
    return renderable;
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Mesh(com.badlogic.gdx.graphics.Mesh) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 15 with Mesh

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

the class SpriteBatch method flush.

@Override
public void flush() {
    if (idx == 0)
        return;
    renderCalls++;
    totalRenderCalls++;
    int spritesInBatch = idx / 20;
    if (spritesInBatch > maxSpritesInBatch)
        maxSpritesInBatch = spritesInBatch;
    int count = spritesInBatch * 6;
    lastTexture.bind();
    Mesh mesh = this.mesh;
    mesh.setVertices(vertices, 0, idx);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(count);
    if (blendingDisabled) {
        Gdx.gl.glDisable(GL20.GL_BLEND);
    } else {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        if (blendSrcFunc != -1)
            Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);
    }
    mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count);
    idx = 0;
}
Also used : Mesh(com.badlogic.gdx.graphics.Mesh)

Aggregations

Mesh (com.badlogic.gdx.graphics.Mesh)32 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)15 Texture (com.badlogic.gdx.graphics.Texture)8 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)8 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Material (com.badlogic.gdx.graphics.g3d.Material)3 MeshPart (com.badlogic.gdx.graphics.g3d.model.MeshPart)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)2 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)2 Vector3 (com.badlogic.gdx.math.Vector3)2 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)2 com.badlogic.gdx.physics.bullet.collision.btShapeHull (com.badlogic.gdx.physics.bullet.collision.btShapeHull)2 PerspectiveCamController (com.badlogic.gdx.tests.utils.PerspectiveCamController)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1