Mesh won`t render.

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();
	}

It’s probably all those improper indents, lack of spaces and generally inconsistent formatting. :confused:

(But in all seriousness)
We need more info than “it wont work”.

I sorry for the lack of info but I am new to opengl .Now I have a big black triangle on the screen.

Doesn’t matter what your experience level is with OpenGL, we still need more code and explanations.

As Rayvolution suggested: try consistently formatting your code. Otherwise people will get confused looking at it. Here, I did it for you this time:

package nl.basvs.launcher.utils;

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();
    }
}

A second thing: it appears like low-level OpenGL may be a bit over your head. I would suggest starting with Java2D, or a framework that does much the work for you like LibGDX.

From your code we cant see whats going on. For that we need at least the camera / projection matrix code and other render code.

Edit: and finally, “Can render the mesh.I have used the tutorial.” does not really make sense. Unless you are just poor in English, try to describe things more clearly or you will not get anywhere asking for help.

Good luck! ;D