/** @return A copy of this VertexAttribute with the same parameters. The {@link #offset} is not copied and must * be recalculated, as is typically done by the {@linkplain VertexAttributes} that owns the VertexAttribute. */ public VertexAttribute copy (){ return new VertexAttribute(usage, numComponents, type, normalized, alias, unit); }
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); }
mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0)); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1, 0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1, 0.5f, 0.5f, 0, 1, 1, 1, 1, 1, 0, -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0}); meshCustomVA = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorPacked(), new VertexAttribute(Usage.TextureCoordinates, 2, GL20.GL_UNSIGNED_SHORT, true, ShaderProgram.TEXCOORD_ATTRIBUTE + "0", 0)); meshCustomVA.setVertices(new float[] { -0.5f, -0.5f, 0, Color.WHITE_FLOAT_BITS, toSingleFloat(0, 1),
@Override protected void initVertices() { /** STARS **/ meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux1 = new Vector3(); maxVertices = 3000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; additionalOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; /** NEBULA **/ // Max of 5000 nebula clouds int maxQuads = 5000; int maxQuadVertices = maxQuads * 4; int maxQuadIndices = maxQuads * 6; quad = new MeshData(); quad.mesh = new Mesh(false, maxQuadVertices, maxQuadIndices, VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0), new VertexAttribute(Usage.Generic, 2, "a_additional")); quad.vertices = new float[maxQuadVertices * (quad.mesh.getVertexAttributes().vertexSize / 4)]; quad.vertexSize = quad.mesh.getVertexAttributes().vertexSize / 4; quad.indices = new short[maxQuadIndices]; }
int maxVertices = numSprites * 6; VertexAttribute[] vertexAttributes = new VertexAttribute[] {VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0)};
terrain = new Mesh(false, vertexCount * 6, 0, new VertexAttributes(VertexAttribute.Position(), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, ShaderProgram.TEXCOORD_ATTRIBUTE + 0)));
@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")); }
public static MaskTextureStruct buildMesh(GDXRenderer gdxRenderer, GDXPolygon polygon){ EarClippingTriangulator triangulator = new EarClippingTriangulator(); List<Vector2> verticesAbsolute = triangulator.computeTriangles(polygon.getVerticesAbsolute()); Mesh mesh = new Mesh(true, verticesAbsolute.size(), 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); Texture texture = gdxRenderer.getTexture(polygon.getResource()); mesh.setVertices(convert(verticesAbsolute, polygon.getCenter())); return new MaskTextureStruct(mesh, texture, polygon); }
/** @return A copy of this VertexAttribute with the same parameters. The {@link #offset} is not copied and must * be recalculated, as is typically done by the {@linkplain VertexAttributes} that owns the VertexAttribute. */ public VertexAttribute copy (){ return new VertexAttribute(usage, numComponents, type, normalized, alias, unit); }
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); }
public static VertexAttribute Position () { return new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE); }
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); }
public static VertexAttribute ColorUnpacked () { return new VertexAttribute(Usage.ColorUnpacked, 4, GL20.GL_FLOAT, false, ShaderProgram.COLOR_ATTRIBUTE); }
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); }
public static VertexAttribute BoneWeight (int unit) { return new VertexAttribute(Usage.BoneWeight, 2, ShaderProgram.BONEWEIGHT_ATTRIBUTE + unit, unit); }
public static VertexAttribute Tangent () { return new VertexAttribute(Usage.Tangent, 3, ShaderProgram.TANGENT_ATTRIBUTE); }
public static VertexAttribute TexCoords (int unit) { return new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + unit, unit); }
public static VertexAttribute Binormal () { return new VertexAttribute(Usage.BiNormal, 3, ShaderProgram.BINORMAL_ATTRIBUTE); }
public static VertexAttribute Normal () { return new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE); }