Skip to main content
gamedev.net
🔒 Locked

GL_ARB_vertex_buffer_object

Started by akn81 Apr 20, 2003 at 4:09 AM 5 replies 1.1k views
Original Post
akn81
akn81
Hi there, is anyone familiar with how to use this extension? I''ve heard that it has replaced VAR, but I don''t understand how to use it. I''m working on a 3d space sim, and was thinking for situations where many identical ships are onscreen perhaps it might be better to upload a single mesh to the video card, then call glTranslatef() for each ship before rendering the mesh. Is that a good idea?
The_Fallen
The_Fallen
Generate a buffer:


  
glGenBuffersARB(1, &m_BufferObject);


Bind the buffer and initilialize it with your geometry data:


  
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_BufferObject);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, memorysize, m_Memory, GL_STATIC_DRAW_ARB);


Or GL_DYNAMIC_DRAW_ARB for a dynamic array.

And for drawing bind your buffer again:


  
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_BufferObject);


Tell OpenGL what data you''ve got:


  
glVertexPointer(3, GL_FLOAT, m_StructureSize, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);


BUFFER_OFFSET is something like this:


  
#define BUFFER_OFFSET(i) ((char *)NULL + (i))


And then draw like this:

  
glDrawElements(mode, count, GL_UNSIGNED_SHORT, indices);
The_Fallen
The_Fallen
And search on developer.nvidia.com, there are some really good papers about that topic.
akn81
akn81
Thanks for giving me the steps, but what is m_BufferObject and m_Memory? I''m sorry I couldn''t find any examples using vertex_buffer_object on Nvidia''s page, at best I got the specification from oss.sgi.com, but I just want a practical example, lets say to draw a cube. Can you help me out with that please?
_DarkWIng_
_DarkWIng_
at the end of extension documentation there are a bunch of examples how to use ARB_VBO with different settings (static/dynamic,....)

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
The_Fallen
The_Fallen
Sorry, here are my variables:


    
GLuint m_BufferObject; // holds the buffer

int memorysize; // total size of vertex memory

char *m_Memory; // pointer to the vertex memory

// (need only a pointer, char not necessary)

int m_StructureSize; // size in bytes of one vertex in memory



And in the call to glDrawElements():


mode = GL_TRIANGLES, GL_TRIANGLE_STRIPS or whatsoever
count = number of vertices
indices = pointer to the index array


[edited by - The_Fallen on April 21, 2003 2:54:33 PM]
akn81
akn81
Thank you! I''ll go and test it out now, if I run into problems I''ll let you know

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.