Example usage for com.badlogic.gdx.graphics Mesh Mesh

List of usage examples for com.badlogic.gdx.graphics Mesh Mesh

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Mesh Mesh.

Prototype

public Mesh(boolean isStatic, int maxVertices, int maxIndices, VertexAttributes attributes) 

Source Link

Document

Creates a new Mesh with the given attributes.

Usage

From source file:airfoil.Airfoil.java

License:Open Source License

/**
 * @return GL_LINES//from   w  w w .j a  v a2  s .  c  o  m
 */
public Mesh getMesh(Geometry geometry) {

    final AirfoilVertices af = this.getModelVertices(geometry);

    final float[] points;
    if (af.hasSection() && Geometry.TB3 == geometry)
        points = af.getSectionMeshLines();
    else
        points = af.getModelMeshLines();

    final int count = (points.length / geometry.dimension.number);

    final Mesh mesh = new Mesh(true, count, 0, VertexAttribute.Position());

    mesh.setVertices(points);

    return mesh;
}

From source file:com.badlogic.gdx.tests.dragome.examples.HelloTriangle.java

License:Apache License

@Override
public void create() {
    String vertexShader = "attribute vec4 vPosition;    \n" + "void main()                  \n"
            + "{                            \n" + "   gl_Position = vPosition;  \n"
            + "}                            \n";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n"
            + "void main()                                  \n"
            + "{                                            \n"
            + "  gl_FragColor = vec4 ( 1.0, 1.0, 1.0, 1.0 );\n" + "}";

    shader = new ShaderProgram(vertexShader, fragmentShader);
    mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "vPosition"));
    float[] vertices = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f };
    mesh.setVertices(vertices);/*from www  .  j  a v  a2  s  .co m*/
}

From source file:com.badlogic.gdx.tests.g3d.HeightField.java

public HeightField(boolean isStatic, int width, int height, boolean smooth, VertexAttributes attributes) {
    this.posPos = attributes.getOffset(Usage.Position, -1);
    this.norPos = attributes.getOffset(Usage.Normal, -1);
    this.uvPos = attributes.getOffset(Usage.TextureCoordinates, -1);
    this.colPos = attributes.getOffset(Usage.ColorUnpacked, -1);
    smooth = smooth || (norPos < 0); // cant have sharp edges without normals

    this.width = width;
    this.height = height;
    this.smooth = smooth;
    this.data = new float[width * height];

    this.stride = attributes.vertexSize / 4;

    final int numVertices = smooth ? width * height : (width - 1) * (height - 1) * 4;
    final int numIndices = (width - 1) * (height - 1) * 6;

    this.mesh = new Mesh(isStatic, numVertices, numIndices, attributes);
    this.vertices = new float[numVertices * stride];

    setIndices();/*from w w w  .  j a v a  2  s . c  om*/
}

From source file:com.badlogic.gdx.tests.lw.PongLW.java

License:Apache License

/**
 * This method sets up all the graphics related stuff like the Meshes, the camera and the Font
 *//*w  w w . j ava2  s  . co m*/
private void setupGraphics() {
    //
    // We first construct the paddle mesh which consists of
    // four 2D vertices forming a vertically elongated rectangle
    // constructed around the origin. We don't use colors, normals
    // texture coordinates or indices. Note that we use a fixed
    // point Mesh here. The paddle has dimensions (10, 60).
    //
    paddleMesh = new Mesh(true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"));
    paddleMesh.setVertices(new float[] { -5, -30, 5, -30, 5, 30, -5, 30 });

    //
    // We do the same for the ball which has dimensions (10,10)
    //
    ballMesh = new Mesh(true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"));
    ballMesh.setVertices(new float[] { -5, -5, 5, -5, 5, 5, -5, 5 });

    //
    // We construct a new font from a system font. We assume
    // Arial is installed on both the desktop and Android.
    //
    // font = Gdx.graphics.newFont("Arial", 30, FontStyle.Plain);
    score = "0 : 0";
    spriteBatch = new SpriteBatch();

    //
    // Finally we construct an {@link OrthographicCamera} which
    // will scale our scene to 480x320 pixels no matter what the
    // real screen dimensions. This will of course squish the scene
    // on devices like the Droid. The screen center will be at (0,0)
    // so that's the reference frame for our scene.
    //
    camera = new OrthographicCamera(480, 320);
}

From source file:com.badlogic.gdx.tests.MyFirstTriangle.java

License:Apache License

@Override
public void create() {
    if (mesh == null) {
        mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3, "a_position"));

        mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0.5f, -0.5f, 0, 0, 0.5f, 0 });
        mesh.setIndices(new short[] { 0, 1, 2 });
    }/*w w  w.  j  a  va2  s .c  o  m*/
}

From source file:com.cyphercove.dayinspace.shared.FullScreenFader.java

License:Apache License

public FullScreenFader(float fadeTime, boolean startOn, float startingAlpha, Color color) {
    this.fadeTime = fadeTime;
    on = startOn;//  ww w  . jav  a  2 s .c om
    alpha = startingAlpha;

    mesh = new Mesh(true, 4, 0, new VertexAttribute(Usage.Position, 3, "a_position"));

    mesh.setVertices(vertices);
    this.color = color;

    createShader();
}

From source file:com.cyphercove.lwptools.core.FullScreenFader.java

License:Apache License

public FullScreenFader(float delay, float fadeTime, Color color) {
    this.delay = delay;
    this.fadeTime = fadeTime;

    mesh = new Mesh(true, 4, 0, new VertexAttribute(Usage.Position, 3, "a_position"));

    mesh.setVertices(vertices);// w  w w  .j ava 2  s  . c o m
    this.color = color;
}

From source file:com.dgzt.core.shape.Shape.java

License:Open Source License

/**
 * Create mesh. The test files can override this method.
 * /*w w w  .j a v a  2s. c  om*/
 * @param isStatic - Is static.
 * @param verticesNum - The number of vertices.
 * @param maxIndices - The max indices.
 * @param vattribs - The attributes.
 */
protected Mesh getMesh(final boolean isStatic, final int verticesNum, final int maxIndices,
        final VertexAttribute... vAttribs) {
    return new Mesh(isStatic, verticesNum, maxIndices, vAttribs);
}

From source file:com.gemserk.commons.gdx.graphics.Gdx2dMeshBuilder.java

License:Apache License

public Mesh build() {

    Mesh mesh = new Mesh(true, numVertices, 0, vertexAttributes);

    float realData[] = new float[numVertices * vertexSize];

    System.arraycopy(vertices, 0, realData, 0, realData.length);
    mesh.setVertices(realData);/*from   w w  w. j av  a 2  s  .  c o m*/

    numSetTexCoords = 0;
    vertexIdx = 0;
    numVertices = 0;

    return mesh;
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java

License:Open Source License

public static Mesh genIcosahedronMesh(float x, float z) {
    Mesh mesh = new Mesh(true, 12, 60, new VertexAttribute(Usage.Position, 3, "a_position"));
    mesh.setVertices(genIcosahedronVertices(x, z));
    mesh.setIndices(genIcosahedronIndicies());

    return mesh;//w  w  w  .  j  a  v  a2s . c o m
}