Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (553)
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  
  VBO Not Rendering  (Read 1666 times)
0 Members and 1 Guest are viewing this topic.
Offline Longarmx
« Posted 2013-02-05 23:44:56 »

I have spent about a week trying to get this code to work. I have gone to about 10 different websites and watched multiple videos on VBOs and VAOs. I think that I am just making a stupid mistake but I am not sure. I just need someone else to look at this code and tell me if something is wrong.

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  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
private float[] vertices = {
      0.0f, 1.0f, 1.0f,  
      0.0f, 0.0f, 1.0f,
      0.5f, 0.0f, 0.0f,  
      0.5f, 1.0f, 0.0f,  
      1.0f, 1.0f, 1.0f,
      1.0f, 0.0f, 1.0f
   };
   
   private float[] indices = {
      0, 1, 2,    // Left Bottom
     2, 3, 0,    // Left Top
     3, 2, 5,    // Right Bottom
     5, 4, 3,   // Right Top
     4, 5, 1,    // Back Bottom
     1, 0, 4,    // Back Top
     0, 3, 4,    // Top
     1, 2, 5      // Bottom
  };
   
   FloatBuffer verticesBuffer;
   FloatBuffer indicesBuffer;
   
   private int indicesCount = 0;
   
   private int vaoid = 0;
   private int vboid = 0;
   private int vboindicesid = 0;
   
   public TriangularPrism(){
      verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
      verticesBuffer.put(vertices);
      verticesBuffer.flip();
     
      indicesBuffer = BufferUtils.createFloatBuffer(indices.length);
      indicesBuffer.put(indices);
      indicesBuffer.flip();
      indicesCount = indices.length;
     
      vaoid = GL30.glGenVertexArrays();
      GL30.glBindVertexArray(vaoid);
     
      vboid = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboid);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
      GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

      GL30.glBindVertexArray(0);
     
      vboindicesid = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboindicesid);
      GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
     
      Util.exitOnGLError("TriangularPrism");
   }

   public void render(){
      GL30.glBindVertexArray(vaoid);
      GL20.glEnableVertexAttribArray(0);
     
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
     
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboindicesid);
      GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
     
      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
     
      GL20.glDisableVertexAttribArray(0);
      GL30.glBindVertexArray(0);
     
      Util.exitOnGLError("TriangularPrism.render");
   }
   
   public void destroy(){
      GL20.glDisableVertexAttribArray(0);
     
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
      GL15.glDeleteBuffers(vboid);
     
      GL30.glBindVertexArray(0);
      GL30.glDeleteVertexArrays(vaoid);
     
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
      GL15.glDeleteBuffers(vboindicesid);
   }


Thank you for everything!
Longarmx

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-02-06 00:24:38 »

You need to use pointers. (glVertexPointer() or glVertexAttribPointer())

Offline Longarmx
« Reply #2 - Posted 2013-02-06 00:25:42 »

You need to use pointers. (glVertexPointer() or glVertexAttribPointer())

Am I not already doing that with glVertexAttribPointer()?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2013-02-06 00:27:44 »

Oh. I didn't see that because it was in a strange place.

I reckon it's a problem with your vertex shader.

Offline Longarmx
« Reply #4 - Posted 2013-02-06 00:30:56 »

I'm not doing anything too fancy at the moment, just passing the position and color around.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
// Fragment Shader
#version 150 core

in vec4 pass_Color;

out vec4 out_Color;

void main(void){
   out_Color = pass_Color;
}

//Vertex Shader
#version 150 core

in vec4 in_Position;
in vec4 in_Color;

out vec4 pass_Color;

void main(void){
    gl_Position = in_Position;
    pass_Color = in_Color;
}

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #5 - Posted 2013-02-06 00:32:50 »

You need to use Attribute variables, not 'In' variables.

And you aren't passing any colour variable to the vertex shader anyway.

Offline Longarmx
« Reply #6 - Posted 2013-02-06 00:35:27 »

I am using a program around the rendering. Does this affect the VBO at all?

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  
public void create(Shader vertShader, Shader fragShader) {
      if(vertShader.getID() == 0 || fragShader.getID() == 0)   return;
      this.vertShader = vertShader;
      this.fragShader = fragShader;
     
      id = ARBShaderObjects.glCreateProgramObjectARB();
     
      if(id == 0) return;
     
      ARBShaderObjects.glAttachObjectARB(id, vertShader.getID());
      ARBShaderObjects.glAttachObjectARB(id, fragShader.getID());
     
      ARBShaderObjects.glLinkProgramARB(id);
      if(ARBShaderObjects.glGetObjectParameteriARB(id, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE){
         System.err.println(Util.getLogInfo(id));
         return;
      }
     
      GL20.glBindAttribLocation(id, 0, "in_Position");
      GL20.glBindAttribLocation(id, 1, "in_Color");
     
      ARBShaderObjects.glValidateProgramARB(id);
      if(ARBShaderObjects.glGetObjectParameteriARB(id, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB) == GL11.GL_FALSE){
         System.err.println(Util.getLogInfo(id));
         return;
      }
   }

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2013-02-06 01:08:43 »

I'm not sure how your shader implementation works. So I can't help you much.

davedes has some good tutorials + source, but I don't have the link.

Try google-ing lwjgl-basics and find the page on Github.

Offline Longarmx
« Reply #8 - Posted 2013-02-06 01:30:28 »

I have spent about a week trying to get this code to work. I have gone to about 10 different websites and watched multiple videos on VBOs and VAOs.

Already have. I have copied down the exact code from LWJGL's wiki to see if VBOs in general weren't working, but they work perfectly. I think that it might be a combination of 3d space with the VBO that is causing the error.

Offline theagentd
« Reply #9 - Posted 2013-02-06 02:18:13 »

You seem a bit confused when it comes to shader attributes. GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); is deprecated. It's used to enable you to send stuff to the built-in gl_Vertex attribute (also deprecated), meaning that it's a batch version of glVertex3f(). Remove all references to it, it's not doing anything at the moment (except throwing an error if you've disabled compatibility mode).

You've also completely misunderstood VAOs. They store all the vertex settings, so there's no need to enable attributes or bind buffers when rendering after you've set it up. First of all, glEnableVertexAttribArray() is also stored in VAOs, so enable it when you create your VAO and get it done with. Your current render code basically does the full VAO setup every time you want to render it, so a lot of work is unneeded. Also, index arrays are also stored in the VAO, so move those to before you unbind the VAO.

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  
   public TriangularPrism(){
      verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
      verticesBuffer.put(vertices);
      verticesBuffer.flip();
     
      indicesBuffer = BufferUtils.createFloatBuffer(indices.length);
      indicesBuffer.put(indices);
      indicesBuffer.flip();
      indicesCount = indices.length;
     
      vaoid = GL30.glGenVertexArrays();
      GL30.glBindVertexArray(vaoid);
     
      vboid = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboid);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
      GL20.glEnableVertexAttribArray(0); //Stored in the VAO so enable it here and you won't have to bother with it later.
     GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
     
      vboindicesid = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboindicesid);
      GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
      //GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); the bind is stored in the VAO so it won't have any effect on the global state

      GL30.glBindVertexArray(0); //Moved here to make sure that the index buffer is also being registered in the VAO.
     
      Util.exitOnGLError("TriangularPrism");
   }

   public void render(){
      GL30.glBindVertexArray(vaoid);
      //GL20.glEnableVertexAttribArray(0); already enabled
     
      //GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); deprecated and useless
     
      //GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboindicesid); already set up
     GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);
      //GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); unneeded since we didn't bind anything
     
      //GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); deprecated
     
      //GL20.glDisableVertexAttribArray(0); unneeded
     GL30.glBindVertexArray(0); //shouldn't be needed since you should always be binding a new VAO before rendering (or else you're using deprecated functionality)
     
      Util.exitOnGLError("TriangularPrism.render");
   }
   
   public void destroy(){
      //GL20.glDisableVertexAttribArray(0); not needed, this setting is stored in the VAO
     
      //GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); nothing's bound in the first place, it was stored in the VAO
     GL15.glDeleteBuffers(vboid);
     
      //GL30.glBindVertexArray(0); shouldn't be needed since you should always be binding a new VAO before rendering (or else you're using deprecated functionality)
     GL30.glDeleteVertexArrays(vaoid);
     
      //GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); stored in the VAO
     GL15.glDeleteBuffers(vboindicesid);
   }



Now, I believe the reason why it's not rendering "anything" is (in addition to the missing index buffer) because you're not passing in a color, so the color attribute is set to black. Try to hardcode the fragment shader to output a specific color and see if it works.


You need to use Attribute variables, not 'In' variables.

And you aren't passing any colour variable to the vertex shader anyway.
Nope, it's called "in" in GLSL 1.50+.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #10 - Posted 2013-02-06 03:11:59 »

I have changed the code to how you showed me and I hard-coded a color but nothing is rendering. Is there any other code that is critical to VBO rendering?

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #11 - Posted 2013-02-06 03:24:16 »

I have changed the code to how you showed me and I hard-coded a color but nothing is rendering. Is there any other code that is critical to VBO rendering?

Argh!!!!!! Accidentally hit the appreciate button.

Anyway, try finding a diagram of how the OpenGL pipeline works.
If one part doesn't work, the whole thing fails creating a big blank space on the screen. Finding what went wrong is annoying.
Try following what theagentd said.

I'm going to go and update my OpenGL techniques...

Offline theagentd
« Reply #12 - Posted 2013-02-06 07:23:19 »

Why are your indices float value? They should be (unsigned) short values! You've also specified the indices as GL_UNSIGNED_BYTE in glDrawElements(). Change that to GL_UNSIGNED_SHORT, and change the index FloatBuffer to a ShortBuffer.

Myomyomyo.
Offline Longarmx
« Reply #13 - Posted 2013-02-06 13:11:39 »

I think that the LWJGL wiki should be revised.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56

Norakomi (42 views)
2014-08-06 19:49:38
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!