Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 621 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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!