use of com.badlogic.gdx.graphics.Mesh 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;
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class GwtTest method create.
@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"));
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class Model method convertMesh.
protected void convertMesh(ModelMesh modelMesh) {
int numIndices = 0;
for (ModelMeshPart part : modelMesh.parts) {
numIndices += part.indices.length;
}
VertexAttributes attributes = new VertexAttributes(modelMesh.attributes);
int numVertices = modelMesh.vertices.length / (attributes.vertexSize / 4);
Mesh mesh = new Mesh(true, numVertices, numIndices, attributes);
meshes.add(mesh);
disposables.add(mesh);
BufferUtils.copy(modelMesh.vertices, mesh.getVerticesBuffer(), modelMesh.vertices.length, 0);
int offset = 0;
mesh.getIndicesBuffer().clear();
for (ModelMeshPart part : modelMesh.parts) {
MeshPart meshPart = new MeshPart();
meshPart.id = part.id;
meshPart.primitiveType = part.primitiveType;
meshPart.offset = offset;
meshPart.size = part.indices.length;
meshPart.mesh = mesh;
mesh.getIndicesBuffer().put(part.indices);
offset += meshPart.size;
meshParts.add(meshPart);
}
mesh.getIndicesBuffer().position(0);
for (MeshPart part : meshParts) part.update();
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class BillboardParticleBatch method allocRenderable.
protected Renderable allocRenderable() {
Renderable renderable = new Renderable();
renderable.meshPart.primitiveType = GL20.GL_TRIANGLES;
renderable.meshPart.offset = 0;
renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture));
renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes);
renderable.meshPart.mesh.setIndices(indices);
renderable.shader = shader;
return renderable;
}
use of com.badlogic.gdx.graphics.Mesh in project libgdx by libgdx.
the class SpriteBatch method flush.
@Override
public void flush() {
if (idx == 0)
return;
renderCalls++;
totalRenderCalls++;
int spritesInBatch = idx / 20;
if (spritesInBatch > maxSpritesInBatch)
maxSpritesInBatch = spritesInBatch;
int count = spritesInBatch * 6;
lastTexture.bind();
Mesh mesh = this.mesh;
mesh.setVertices(vertices, 0, idx);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(count);
if (blendingDisabled) {
Gdx.gl.glDisable(GL20.GL_BLEND);
} else {
Gdx.gl.glEnable(GL20.GL_BLEND);
if (blendSrcFunc != -1)
Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);
}
mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count);
idx = 0;
}
Aggregations