Search in sources :

Example 1 with TextureArray

use of com.badlogic.gdx.graphics.TextureArray 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();
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttributes(com.badlogic.gdx.graphics.VertexAttributes) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) TextureArray(com.badlogic.gdx.graphics.TextureArray) Mesh(com.badlogic.gdx.graphics.Mesh) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Aggregations

Mesh (com.badlogic.gdx.graphics.Mesh)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextureArray (com.badlogic.gdx.graphics.TextureArray)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 FirstPersonCameraController (com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController)1 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)1