Can render the mesh.I have used the tutorial.
public class ShapeTerrain {
private Mesh mesh;
private Texture texture;
private ShaderProgram shader ;
PolygonShape poly;
PolygonRegion po;
TextureRegion texreg;
static 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" ;
static 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" +
"}";
protected static ShaderProgram createMeshShader() {
ShaderProgram.pedantic = false;
ShaderProgram shader = new ShaderProgram(vertexShader, fragmentShader);
return shader;
}
public ShapeTerrain()
{
mesh = new Mesh(true, 3, 3,
new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
mesh.setVertices(new float[] { -5f, -5f, 0, 0.2f, 0.3f, 0.4f, 1f, 0, 1,
5f, -5f, 0, 0.1f, 0.2f, 0.1f, 1f, 1, 1,
0, 5f, 0, 0, 0.4f, 0.5f, 0.5f, 1f, 0 });
mesh.setIndices(new short[] { 0, 1, 2 });
texture = new Texture(Gdx.files.internal("data/badlogic.png"));
shader = ImmediateModeRenderer20.createDefaultShader(true,true,0);
}
public void render(SpriteBatch batch,PolygonSpriteBatch poly)
{
texture.bind();
shader.begin();
mesh.render(shader, GL20.GL_TRIANGLES);
shader.end();
}