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 (568)
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  
  Issue creating or rendering VBO  (Read 285 times)
0 Members and 1 Guest are viewing this topic.
Offline saucymeatman
« Posted 2014-03-01 02:36:08 »

This is where I create the VBO :
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  
   public void generateVBO() {
      vertexBufferVertices = 0;
      textureBufferVertices = 0;
      for (Quad quad : quads) {
         if (quad != null) {
            for (Vertex3f vert : quad.vertices) {
               vertexBufferVertices ++;
            }
            for (Vector2f vert : quad.textureQuardinates) {
               textureBufferVertices ++;
            }
         }
      }
     
      FloatBuffer data = BufferUtils.createFloatBuffer(vertexBufferVertices*3+textureBufferVertices*2);
      for (Quad quad : quads) {
         if (quad != null) {
            for (Vertex3f vert : quad.vertices) {
               data.put(vert.x()).put(vert.y()).put(vert.z());
            }
            for (Vector2f vert : quad.textureQuardinates) {
               data.put(vert.x).put(vert.y);
            }
         }
      }
      data.flip();
     
      vertexBufferObjectID = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferObjectID);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
   }


And here is where I render it :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
         GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferObjectID);
         
         int stride = (3 << 2) + (2 << 2);
         int offset = 0;
         
         GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
         GL11.glVertexPointer(3, GL11.GL_FLOAT, stride, offset);
         offset += (3 << 2);
         
         GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
         GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, offset);
         offset += (2 << 2);
         
         
         GL11.glDrawArrays(GL11.GL_QUADS, 0, vertexBufferVertices);
         
         GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
         GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);


Im sorry for bothering you guys for help, but I cant figure out what I'm doing wrong. Im sure its right in front of me.

EDIT :
Should have been more clear, nothing crashes, but its rending strangely. I suspect it is the issue with the stride/offset.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-03-01 03:02:26 »

What's the issue? Is the code failing (IE crashing) or can you just not see anything?

Offline The Lion King
« Reply #2 - Posted 2014-03-01 03:09:45 »

Your doing your stride and offset wrong. Stride should be 3*4 + 2*4.

First offset change should be offset += 3*4.  

Second should be offset += 2*4

[Edit] corrected

"You have to want it more than you want to breath, then you will be successful"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline saucymeatman
« Reply #3 - Posted 2014-03-01 03:56:45 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
         int stride = 3*2*4 + 2*2*4;
         int offset = 0;
         
         GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
         GL11.glVertexPointer(3, GL11.GL_FLOAT, stride, offset);
         offset += 3*2*4;
         
         GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
         GL11.glTexCoordPointer(2, GL11.GL_FLOAT, stride, offset);
         offset += 2*2*4;

Like so?
This is not working either. :{
I understand where the 3*2 comes from but where s the 4 coming from in :
offset += 3*2*4;
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


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


« Reply #4 - Posted 2014-03-01 04:05:00 »

The 4 is the size of a float in bytes.

You need to be passing the size in bytes

Offline The Lion King
« Reply #5 - Posted 2014-03-01 04:07:44 »

Sorry my mistake

Stride = 3*4 + 2 *4;

Offset += 3*4;

Offset += 2*4;

"You have to want it more than you want to breath, then you will be successful"
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.

Riven (9 views)
2014-10-02 14:36:20

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

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

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

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

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

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

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

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

UprightPath (53 views)
2014-09-20 20:14:06
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!