use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class FloatTextureTest method createQuad.
private void createQuad() {
if (quad != null)
return;
quad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
quad.setVertices(new float[] { -1, -1, 0, 1, 1, 1, 1, 0, 1, 1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 0 });
quad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class MipMap2D method create.
@Override
public void create() {
String vertexShader = "uniform float u_offset; \n" + "attribute vec4 a_position; \n" + "attribute vec2 a_texCoord; \n" + "varying vec2 v_texCoord; \n" + "void main() \n" + "{ \n" + " gl_Position = a_position; \n" + " gl_Position.x += u_offset;\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" + "void main() \n" + "{ \n" + " gl_FragColor = texture2D( s_texture, v_texCoord );\n" + "} \n";
shader = new ShaderProgram(vertexShader, fragmentShader);
mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 4, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));
float[] vertices = { // Position 0
-0.5f, // Position 0
0.5f, // Position 0
0.0f, // Position 0
1.5f, // TexCoord 0
0.0f, // TexCoord 0
0.0f, // Position 1
-0.5f, // Position 1
-0.5f, // Position 1
0.0f, // Position 1
0.75f, // TexCoord 1
0.0f, // TexCoord 1
1.0f, // Position 2
0.5f, // Position 2
-0.5f, // Position 2
0.0f, // Position 2
0.75f, // TexCoord 2
1.0f, // TexCoord 2
1.0f, // Position 3
0.5f, // Position 3
0.5f, // Position 3
0.0f, // Position 3
1.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 TextureArrayTest method create.
@Override
public void create() {
GL30Profiler.enable();
ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_EXT_texture_array : enable\n" : "#version 300 es\n";
String[] texPaths = new String[] { "data/g3d/materials/Searing Gorge.jpg", "data/g3d/materials/Lava Cracks.jpg", "data/g3d/materials/Deep Fire.jpg" };
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(8, 10f, 20f);
camera.lookAt(10, 0, 10);
camera.up.set(0, 1, 0);
camera.update();
cameraController = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(cameraController);
textureArray = new TextureArray(texPaths);
textureArray.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
shaderProgram = new ShaderProgram(Gdx.files.internal("data/shaders/texturearray.vert"), Gdx.files.internal("data/shaders/texturearray.frag"));
System.out.println(shaderProgram.getLog());
int vertexStride = 6;
int vertexCount = 100 * 100;
terrain = new Mesh(false, vertexCount * 6, 0, new VertexAttributes(VertexAttribute.Position(), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, ShaderProgram.TEXCOORD_ATTRIBUTE + 0)));
Pixmap data = new Pixmap(Gdx.files.internal("data/g3d/heightmap.png"));
float[] vertices = new float[vertexCount * vertexStride * 6];
int idx = 0;
for (int i = 0; i < 100 - 1; i++) {
for (int j = 0; j < 100 - 1; j++) {
idx = addVertex(i, j, vertices, data, idx);
idx = addVertex(i, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j, vertices, data, idx);
idx = addVertex(i, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j + 1, vertices, data, idx);
idx = addVertex(i + 1, j, vertices, data, idx);
}
}
terrain.setVertices(vertices);
data.dispose();
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class btIndexedMesh method set.
/** Convenience method to set this btIndexedMesh to the specified {@link Mesh}
* The specified mesh must be indexed and triangulated and must outlive this btIndexedMesh.
* The buffers for the vertices and indices are shared amonst both. */
public void set(final Object tag, final Mesh mesh, int offset, int count) {
if ((count <= 0) || ((count % 3) != 0))
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh must be indexed and triangulated");
VertexAttribute posAttr = mesh.getVertexAttribute(Usage.Position);
if (posAttr == null)
throw new com.badlogic.gdx.utils.GdxRuntimeException("Mesh doesn't have a position attribute");
set(tag, mesh.getVerticesBuffer(), mesh.getVertexSize(), mesh.getNumVertices(), posAttr.offset, mesh.getIndicesBuffer(), offset, count);
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class VertexArray method bind.
@Override
public void bind(final ShaderProgram shader, final int[] locations) {
final int numAttributes = attributes.size();
byteBuffer.limit(buffer.limit() * 4);
if (locations == null) {
for (int i = 0; i < numAttributes; i++) {
final VertexAttribute attribute = attributes.get(i);
final int location = shader.getAttributeLocation(attribute.alias);
if (location < 0)
continue;
shader.enableVertexAttribute(location);
byteBuffer.position(attribute.offset);
shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, byteBuffer);
}
} else {
for (int i = 0; i < numAttributes; i++) {
final VertexAttribute attribute = attributes.get(i);
final int location = locations[i];
if (location < 0)
continue;
shader.enableVertexAttribute(location);
byteBuffer.position(attribute.offset);
shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, byteBuffer);
}
}
isBound = true;
}
Aggregations