Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (593)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
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 721 times)
0 Members and 1 Guest are viewing this topic.
Offline Ffelagund

Senior Newbie





« Posted 2005-12-28 11: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 09: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.

 
deepthought (29 views)
2015-06-30 15:39:44

deepthought (31 views)
2015-06-30 15:39:09

deepthought (41 views)
2015-06-30 15:36:52

Za\'Anzabar (21 views)
2015-06-29 05:44:54

TritonDreyja (36 views)
2015-06-24 17:10:40

CopyableCougar4 (35 views)
2015-06-23 00:34:45

BurntPizza (39 views)
2015-06-21 20:36:46

cookiecompiler (81 views)
2015-06-11 15:42:53

cookiecompiler (45 views)
2015-06-11 15:41:14

NegativeZero (74 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!