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  
  Trouble creating/useing a VBO  (Read 194 times)
0 Members and 1 Guest are viewing this topic.
Offline saucymeatman
« Posted 2014-02-17 01:51:31 »

Nothing is rendering, or if it is, then it is rendering so far away that it is clipped.
Not sure what I'm doing wrong, probably just a rookie mistake! But a gold star to the man who can figure it out.

vertices is an array of instances of the class Vertex, which stores a location which can be retrieved with Vertex.x(), Vertex.y(), or Vertex.z().

This is where I generate the VBO :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   public void generateVBO() {
      vertexBufferVertices = vertices.length;
      float[] verticesData = new float[vertices.length*3];
      int i = 0;
      for (Vertex vert : vertices) {
         verticesData[i] = vert.x();
         verticesData[i+1] = vert.y();
         verticesData[i+2] = vert.z();
         i += 3;
      }
      FloatBuffer data = BufferUtils.createFloatBuffer(verticesData.length);
      data.put(verticesData);
     
      vertexBufferObjectID = GL15.glGenBuffers();
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferObjectID);
      GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
   }


The render method :
1  
2  
3  
4  
5  
6  
7  
   public void render() {
      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
      GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBufferObjectID);
      GL11.glVertexPointer(3, GL11.GL_FLOAT, 12, 0);
     
      GL11.glDrawArrays(GL11.GL_QUADS, 0, vertexBufferVertices);
   }


Some things you can be sure of :
-vertexBufferObjectID is a int that is not edited between generateVBO() and
    render().
-vertices.length is 12
-Both render() and generateVBO() are being called in the correct order.
-generateVBO() is only called once.

Thanks in advance to anyone taking the time to reply!
Offline Longarmx
« Reply #1 - Posted 2014-02-17 02:25:47 »

You should be calling
data.flip();
after put all the vertices in the FloatBuffer. Pointing

Offline saucymeatman
« Reply #2 - Posted 2014-02-17 03:06:08 »

Thanks!
That resolved the issue that I posted about.

A shiny gold star for you!
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!