Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mesh won`t render.  (Read 374 times)
0 Members and 1 Guest are viewing this topic.
Offline hhfjkehfe

Senior Newbie





« Posted 2014-04-17 06:57:47 »

Can render the mesh.I have used the tutorial.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
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();
   }
Offline Rayvolution

JGO Kernel


Medals: 208
Projects: 2
Exp: 1 year


Resident Crazyman


« Reply #1 - Posted 2014-04-17 07:09:04 »

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



...



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

- Raymond "Rayvolution" Doerr.
Retro-Pixel Castles - Survival Sim/Builder/Roguelike!
LIVE-STREAMING DEVELOPMENT: http://www.twitch.tv/SG_Rayvolution
Offline hhfjkehfe

Senior Newbie





« Reply #2 - Posted 2014-04-17 07:20:49 »

I sorry for the lack of info but I am new to opengl .Now I have a big black triangle on the screen.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-04-17 13:22:30 »

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

Offline Grunnt

JGO Wizard


Medals: 70
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #4 - Posted 2014-04-17 13:55:49 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
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!  Grin

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!