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;
}
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);
}
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_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, 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;
}
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);
}
}
}
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);
}
Aggregations