Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  More VBO problems  (Read 505 times)
0 Members and 1 Guest are viewing this topic.
Offline Ffelagund

Senior Newbie





« Posted 2005-12-28 12:37:22 »

Hello, after find how to set a vertex buffer using an offset (my previous post) and spending a whole morning (with C I did it in 5 minutes...) I couldn't get the VBO running :/
My purpose is join all small buffers in a big VBO buffer, and in the render loop only change the  indices's vbo of the current drawn mesh. My app doesn't crash, but doesn't draw anything... perhaps I am missing something about nio buffers of something like that.

All of the following code is made after many hours of debug and tests, so it is not optimal at all. I know that there are better methods to perform the following tasks, but I wanted to make all as simple as possible to minimize the problems.

Well, here is where I join all objects (assume that the object's data is right, because with standard VA all is drawn correctly)
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  
    int vertexCount = 0;
    for(int i=0;i<m_meshes.length;i++)
      vertexCount += m_meshes[i].GetNumberOfVertices();
   
    float vert[] = new float[vertexCount*3];
       
    int index = 0;
    int indexOffset = 0;
    long offset = 0;
    for(int i=0;i<m_meshes.length;i++)
    {
      float v[] = m_meshes[i].GetVertices();
      for(int j=0;j<v.length;j++)
      {
        vert[index++] = v[j];
      }
      m_meshes[i].SetOffset(offset);
      m_meshes[i].BuildIndexVBO(indexOffset);
      offset += m_meshes[i].GetNumberOfVertices() * 3 * 4; //OFFSET IS COMPUTED IN BYTES (3 = xyz, 4 = 4 bytes per float)
     indexOffset += m_meshes[i].GetNumberOfVertices();
    }
   
    m_vboGeom = new int[1];
    FloatBuffer vertices = ByteBuffer.allocateDirect((vertexCount * 3) * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();    
    vertices.put(vert);
    gl.glGenBuffers(1, m_vboGeom);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, m_vboGeom[0]);
    gl.glBufferData(GL.GL_ARRAY_BUFFER, vertexCount * 3 * 4, vertices, GL.GL_STATIC_DRAW);
   

    the SetOffset function only performs an asignement to an internal field, for later use

    BUILDINDEXVBO FUNCTION
  public void BuildIndexVBO(int indexoffset)
  {
    for(int i=0;i<m_indexCount;i++)
      m_indices[i] += indexoffset;
    IntBuffer buffer = ByteBuffer.allocateDirect(m_indexCount * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); //4 = 4 bytes per int
   gl.glGenBuffers(1, m_vboIndex);
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, m_vboIndex[0]);  
    gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, m_indexCount * 4, buffer, GL.GL_STATIC_DRAW);    
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
  }

DRAW LOOP
 
    gl.glEnableClientState(GL.GL_VERTEX_ARRAY);    
    for(int i=0;i<m_meshes.length;i++)      
    {
       gl.glPushMatrix();                                                        
            gl.glMultMatrixf(m_meshes[i].TM);    
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, m_vboGeom[0]);    
            ByteBuffer offsetBuffer = BufferUtils.bufferOffset(m_meshes[i].m_vboOffset);  //this offset is the value setted with the SetOffset() function
           gl.glVertexPointer(3, GL.GL_FLOAT, 0, offsetBuffer);
            gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, m_meshes[i].m_vboIndex[0]);
            gl.glDrawElements(GL.GL_TRIANGLES,m_meshes[i].m_indexCount,GL.GL_UNSIGNED_INT,(Buffer) null);      
        gl.glPopMatrix();
    }
    gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
    gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);      
    gl.glDisableClientState(GL.GL_VERTEX_ARRAY);      


Any help will be appreciated, I am really lost with this issue Sad
Offline Ffelagund

Senior Newbie





« Reply #1 - Posted 2005-12-29 10:35:09 »

Found the problem. I had to bind only once the vertices's VBO with offset 0. I already had precalculated the offset in the indices.
I've mixed the concepts  Grin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (81 views)
2013-05-17 21:29:12

alaslipknot (91 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.239 seconds with 20 queries.