Results 1 to 2 of 2

Thread: VBO Java

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2009
    Posts
    1

    VBO Java

    Hey there
    after having decided to increase my modelloader's performance and thus having implemented displaylists, i now changed to VBOs. Sadly they don't work out..

    I simply don't get my mistake, although i have browsed a lot of tuts and specs..

    I calculate the VBO:
    Code :
    		VBOVertices = new int[1];
    		VBOIndices = new int[1];
    		int vertexCount = meshes[0].faces.length*3;
     
     
    		gl.glGenBuffersARB(1, VBOVertices, 0);							
    		gl.glGenBuffersARB(1, VBOIndices, 0);							
            gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0]);			
            gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, VBOIndices[0]);			
     
     
     
    		FloatBuffer tmpFBuffer = FloatBuffer.allocate(meshes[0].vertices.length*3);
     
    		for (int i=0; i < meshes[0].vertices.length; i++)
    		{
    			tmpFBuffer.put(meshes[0].vertices[i].vector.x);
    			tmpFBuffer.put(meshes[0].vertices[i].vector.y);
    			tmpFBuffer.put(meshes[0].vertices[i].vector.z);
    		}
    		tmpFBuffer.flip();
     
     
     
            gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, meshes[0].vertices.length * 3 * BufferUtil.SIZEOF_FLOAT, tmpFBuffer, GL.GL_STATIC_DRAW_ARB);
     
            IntBuffer tmpIBuffer = IntBuffer.allocate(meshes[0].faces.length*3);
     
    		for (int i=0; i < meshes[0].vertices.length; i++)
    		{
    			tmpIBuffer.put(meshes[0].faces[i].v1);
    			tmpIBuffer.put(meshes[0].faces[i].v2);
    			tmpIBuffer.put(meshes[0].faces[i].v3);
    		}
    		tmpIBuffer.flip();
     
     
     
            gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, meshes[0].vertices.length * 3 * BufferUtil.SIZEOF_FLOAT, tmpIBuffer, GL.GL_STATIC_DRAW_ARB);
     
            VBOCalculated = true;

    and render it:
    Code :
    		if (!VBOCalculated)
    			return;
    		gl.glDisable(GL.GL_TEXTURE_2D);
    		gl.glDisable(GL.GL_LIGHTING);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);							
     
            gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0]);
            gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, VBOIndices[0]);
            gl.glInterleavedArrays(GL.GL_V3F, 0, 0);
     
            gl.glDrawElements(GL.GL_TRIANGLES, meshes[0].faces.length*3, GL.GL_UNSIGNED_INT, 0);
     
     
     
            gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
    Though the screen remains black. Do you have any hints?
    Thanks in advance

  2. #2
    Member Contributor Coolcat's Avatar
    Join Date
    Oct 2009
    Location
    NRW, Germany
    Posts
    85

    Re: VBO Java

    1. Your for-Loop over faces does actually run from 0 to meshes[0].vertices.length

    2. You are using the wrong size when creating your elements buffer, I think you need this:
    Code :
    meshes[0].faces.length * 3 * BufferUtil.SIZEOF_UNSIGNED_INT

    However, you should see at least something...some standard tips:
    • Try changing your clear-color. Maybe you just rendering black triangles on black screen. E.g.
      Code :
      glClearColor(69.0/255.0, 165.0/255.0, 255.0/255.0, 0.0);
    • Try to disable backface culling:
      Code :
      glDisable(GL_CULL_FACE);

Similar Threads

  1. 3d java
    By bluff in forum OpenGL: Windows
    Replies: 4
    Last Post: 11-28-2006, 12:28 AM
  2. java
    By bigrockcrasher in forum OpenGL: User Software
    Replies: 1
    Last Post: 03-05-2006, 08:21 AM
  3. Java
    By JanHH in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-15-2003, 04:36 AM
  4. VB OR JAVA???
    By Ali in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-30-2002, 05:03 AM
  5. Java vs C#
    By Music_Man in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-03-2002, 11:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean