use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class ImmediateModeRenderer20 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 MeshShaderTest method create.
@Override
public void create() {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(1, 1, 1, 1); \n" + " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) {
Gdx.app.log("ShaderTest", shader.getLog());
Gdx.app.exit();
}
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 });
mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
//Mesh with texCoords wearing a pair of shorts. :)
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, FLOAT_WHITE, toSingleFloat(0, 1), 0.5f, -0.5f, 0, FLOAT_WHITE, toSingleFloat(1, 1), 0.5f, 0.5f, 0, FLOAT_WHITE, toSingleFloat(1, 0), -0.5f, 0.5f, 0, FLOAT_WHITE, toSingleFloat(0, 0) });
meshCustomVA.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
texture = new Texture(Gdx.files.internal("data/bobrgb888-32x32.png"));
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class MipMapTest method create.
@Override
public void create() {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0, 1.5f, 1.5f);
camera.lookAt(0, 0, 0);
camera.update();
controller = new PerspectiveCamController(camera);
mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
mesh.setVertices(new float[] { -1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0 });
mesh.setIndices(new short[] { 0, 1, 2, 3 });
shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal("data/shaders/flattex-frag.glsl").readString());
if (!shader.isCompiled())
throw new GdxRuntimeException("shader error: " + shader.getLog());
textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
MipMapGenerator.setUseHardwareMipMap(false);
textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
currTexture = textureHW;
createUI();
multiplexer = new InputMultiplexer();
Gdx.input.setInputProcessor(multiplexer);
multiplexer.addProcessor(ui);
multiplexer.addProcessor(controller);
}
use of com.badlogic.gdx.graphics.VertexAttribute in project commons-gdx by gemserk.
the class MeshUtils method changeColors.
/**
* Sets the colors of the vertices of the mesh.
*
* @param mesh
* The Mesh to be modified.
* @param colors
* The new vertex colors.
* @param verticesCache
* An array to contain all the vertices of the mesh size should be (mesh.getNumVertices()*mesh.getVertexSize()/4). This is to avoid GC
*/
public static Mesh changeColors(Mesh mesh, float[] colors, float[] verticesCache) {
VertexAttribute posAttr = mesh.getVertexAttribute(Usage.ColorPacked);
int offset = posAttr.offset / 4;
int numVertices = mesh.getNumVertices();
int vertexSize = mesh.getVertexSize() / 4;
mesh.getVertices(verticesCache);
int idx = offset;
for (int i = 0; i < numVertices; i++) {
verticesCache[idx] = colors[i];
idx += vertexSize;
}
mesh.setVertices(verticesCache);
return mesh;
}
use of com.badlogic.gdx.graphics.VertexAttribute in project commons-gdx by gemserk.
the class MeshUtils method translate.
/**
* Translates the Mesh the specified x and y coordinates.
*
* @param mesh
* The Mesh to be modified.
* @param x
* The x coordinate to be translated.
* @param y
* The y coordinate to be translated.
*/
public static Mesh translate(Mesh mesh, float x, float y) {
VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);
int offset = posAttr.offset / 4;
int numVertices = mesh.getNumVertices();
int vertexSize = mesh.getVertexSize() / 4;
float[] vertices = new float[numVertices * vertexSize];
mesh.getVertices(vertices);
int idx = offset;
for (int i = 0; i < numVertices; i++) {
vertices[idx] += x;
vertices[idx + 1] += y;
idx += vertexSize;
}
mesh.setVertices(vertices);
return mesh;
}
Aggregations