use of com.badlogic.gdx.graphics.VertexAttribute in project commons-gdx by gemserk.
the class Gdx2dMeshBuilder method buildVertexAttributes.
private VertexAttribute[] buildVertexAttributes(boolean hasNormals, boolean hasColor, int numTexCoords) {
Array<VertexAttribute> attribs = new Array<VertexAttribute>();
attribs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if (hasNormals)
attribs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if (hasColor)
attribs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
for (int i = 0; i < numTexCoords; i++) {
attribs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i));
}
VertexAttribute[] array = new VertexAttribute[attribs.size];
for (int i = 0; i < attribs.size; i++) array[i] = attribs.get(i);
return array;
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class ProjectiveTextureTest method setupScene.
public void setupScene() {
plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
plane.setVertices(new float[] { -10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0 });
plane.setIndices(new short[] { 3, 2, 1, 1, 0, 3 });
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 5, 10);
cam.lookAt(0, 0, 0);
cam.update();
controller = new PerspectiveCamController(cam);
projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
projector.position.set(2, 3, 2);
projector.lookAt(0, 0, 0);
projector.normalizeUp();
projector.update();
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class ShaderMultitextureTest method create.
@Override
public void create() {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec2 a_texCoord; \n" + "varying vec2 v_texCoord; \n" + "void main() \n" + "{ \n" + " gl_Position = a_position; \n" + " v_texCoord = a_texCoord; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec2 v_texCoord; \n" + "uniform sampler2D s_texture; \n" + "uniform sampler2D s_texture2; \n" + "void main() \n" + "{ \n" + " gl_FragColor = texture2D( s_texture, v_texCoord ) * texture2D( s_texture2, v_texCoord);\n" + "} \n";
shader = new ShaderProgram(vertexShader, fragmentShader);
mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));
float[] vertices = { // Position 0
-0.5f, // Position 0
0.5f, // TexCoord 0
0.0f, // TexCoord 0
0.0f, // Position 1
-0.5f, // Position 1
-0.5f, // TexCoord 1
0.0f, // TexCoord 1
1.0f, // Position 2
0.5f, // Position 2
-0.5f, // TexCoord 2
1.0f, // TexCoord 2
1.0f, // Position 3
0.5f, // Position 3
0.5f, // TexCoord 3
1.0f, // TexCoord 3
0.0f };
short[] indices = { 0, 1, 2, 0, 2, 3 };
mesh.setVertices(vertices);
mesh.setIndices(indices);
createTexture();
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class SoftBodyTest method create.
@Override
public void create() {
super.create();
world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
float x0 = -2f, y0 = 6f, z0 = -2f;
float x1 = 8f, y1 = 6f, z1 = 8f;
Vector3 patch00 = new Vector3(x0, y0, z0);
Vector3 patch10 = new Vector3(x1, y1, z0);
Vector3 patch01 = new Vector3(x0, y0, z1);
Vector3 patch11 = new Vector3(x1, y1, z1);
softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
softBody.takeOwnership();
softBody.setTotalMass(100f);
((btSoftRigidDynamicsWorld) (world.collisionWorld)).addSoftBody(softBody);
final int vertCount = softBody.getNodeCount();
final int faceCount = softBody.getFaceCount();
mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final int vertSize = mesh.getVertexSize() / 4;
mesh.getVerticesBuffer().position(0);
mesh.getVerticesBuffer().limit(vertCount * vertSize);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(faceCount * 3);
softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
softBody.getIndices(mesh.getIndicesBuffer(), faceCount);
final float[] verts = new float[vertCount * vertSize];
final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
mesh.getVertices(verts);
for (int i = 0; i < vertCount; i++) {
verts[i * vertSize + normalOffset] = 0f;
verts[i * vertSize + normalOffset + 1] = 1f;
verts[i * vertSize + normalOffset + 2] = 0f;
verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
}
mesh.setVertices(verts);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
ModelBuilder builder = new ModelBuilder();
builder.begin();
builder.part(new MeshPart("", mesh, 0, mesh.getNumIndices(), GL20.GL_TRIANGLES), new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
model = builder.end();
instance = new ModelInstance(model);
world.add(new BulletEntity(instance, null));
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class DecalBatch method initialize.
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full.
*
* @param size Maximum size of decal objects to hold in memory */
public void initialize(int size) {
vertices = new float[size * Decal.SIZE];
Mesh.VertexDataType vertexDataType = Mesh.VertexDataType.VertexArray;
if (Gdx.gl30 != null) {
vertexDataType = Mesh.VertexDataType.VertexBufferObjectWithVAO;
}
mesh = new Mesh(vertexDataType, false, size * 4, size * 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
short[] indices = new short[size * 6];
int v = 0;
for (int i = 0; i < indices.length; i += 6, v += 4) {
indices[i] = (short) (v);
indices[i + 1] = (short) (v + 2);
indices[i + 2] = (short) (v + 1);
indices[i + 3] = (short) (v + 1);
indices[i + 4] = (short) (v + 2);
indices[i + 5] = (short) (v + 3);
}
mesh.setIndices(indices);
}
Aggregations