Search in sources :

Example 6 with VertexAttribute

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

the class MultipleRenderTargetTest method createFullScreenQuad.

public Mesh createFullScreenQuad() {
    float[] verts = new float[20];
    int i = 0;
    verts[i++] = -1;
    verts[i++] = -1;
    verts[i++] = 0;
    verts[i++] = 0f;
    verts[i++] = 0f;
    verts[i++] = 1f;
    verts[i++] = -1;
    verts[i++] = 0;
    verts[i++] = 1f;
    verts[i++] = 0f;
    verts[i++] = 1f;
    verts[i++] = 1f;
    verts[i++] = 0;
    verts[i++] = 1f;
    verts[i++] = 1f;
    verts[i++] = -1;
    verts[i++] = 1f;
    verts[i++] = 0;
    verts[i++] = 0f;
    verts[i++] = 1f;
    Mesh mesh = new Mesh(true, 4, 0, new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
    mesh.setVertices(verts);
    return mesh;
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh)

Example 7 with VertexAttribute

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

the class HelloTriangle method create.

@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);
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) Mesh(com.badlogic.gdx.graphics.Mesh)

Example 8 with VertexAttribute

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

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

the class BaseShader method init.

/** Initialize this shader, causing all registered uniforms/attributes to be fetched. */
public void init(final ShaderProgram program, final Renderable renderable) {
    if (locations != null)
        throw new GdxRuntimeException("Already initialized");
    if (!program.isCompiled())
        throw new GdxRuntimeException(program.getLog());
    this.program = program;
    final int n = uniforms.size;
    locations = new int[n];
    for (int i = 0; i < n; i++) {
        final String input = uniforms.get(i);
        final Validator validator = validators.get(i);
        final Setter setter = setters.get(i);
        if (validator != null && !validator.validate(this, i, renderable))
            locations[i] = -1;
        else {
            locations[i] = program.fetchUniformLocation(input, false);
            if (locations[i] >= 0 && setter != null) {
                if (setter.isGlobal(this, i))
                    globalUniforms.add(i);
                else
                    localUniforms.add(i);
            }
        }
        if (locations[i] < 0) {
            validators.set(i, null);
            setters.set(i, null);
        }
    }
    if (renderable != null) {
        final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
        final int c = attrs.size();
        for (int i = 0; i < c; i++) {
            final VertexAttribute attr = attrs.get(i);
            final int location = program.getAttributeLocation(attr.alias);
            if (location >= 0)
                attributes.put(attr.getKey(), location);
        }
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute)

Example 10 with VertexAttribute

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

the class G3dModelLoader method parseAttributes.

private VertexAttribute[] parseAttributes(JsonValue attributes) {
    Array<VertexAttribute> vertexAttributes = new Array<VertexAttribute>();
    int unit = 0;
    int blendWeightCount = 0;
    for (JsonValue value = attributes.child; value != null; value = value.next) {
        String attribute = value.asString();
        String attr = (String) attribute;
        if (attr.equals("POSITION")) {
            vertexAttributes.add(VertexAttribute.Position());
        } else if (attr.equals("NORMAL")) {
            vertexAttributes.add(VertexAttribute.Normal());
        } else if (attr.equals("COLOR")) {
            vertexAttributes.add(VertexAttribute.ColorUnpacked());
        } else if (attr.equals("COLORPACKED")) {
            vertexAttributes.add(VertexAttribute.ColorPacked());
        } else if (attr.equals("TANGENT")) {
            vertexAttributes.add(VertexAttribute.Tangent());
        } else if (attr.equals("BINORMAL")) {
            vertexAttributes.add(VertexAttribute.Binormal());
        } else if (attr.startsWith("TEXCOORD")) {
            vertexAttributes.add(VertexAttribute.TexCoords(unit++));
        } else if (attr.startsWith("BLENDWEIGHT")) {
            vertexAttributes.add(VertexAttribute.BoneWeight(blendWeightCount++));
        } else {
            throw new GdxRuntimeException("Unknown vertex attribute '" + attr + "', should be one of position, normal, uv, tangent or binormal");
        }
    }
    return vertexAttributes.toArray(VertexAttribute.class);
}
Also used : Array(com.badlogic.gdx.utils.Array) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) JsonValue(com.badlogic.gdx.utils.JsonValue)

Aggregations

VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)33 Mesh (com.badlogic.gdx.graphics.Mesh)15 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)9 Texture (com.badlogic.gdx.graphics.Texture)8 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)6 Array (com.badlogic.gdx.utils.Array)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 Vector3 (com.badlogic.gdx.math.Vector3)3 GL20 (com.badlogic.gdx.graphics.GL20)2 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Attributes (com.badlogic.gdx.graphics.g3d.Attributes)2 IndexBufferObject (com.badlogic.gdx.graphics.glutils.IndexBufferObject)2 VertexBufferObject (com.badlogic.gdx.graphics.glutils.VertexBufferObject)2 PerspectiveCamController (com.badlogic.gdx.tests.utils.PerspectiveCamController)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextureArray (com.badlogic.gdx.graphics.TextureArray)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Environment (com.badlogic.gdx.graphics.g3d.Environment)1