1
\$\begingroup\$

So I am currently creating a game based on static voxels, there is no manipulation of voxels, which allows me to optimize it more.

Now, my friend was kind enough to teach me modern OpenGL. Currently I use OpenGL 1.1, and the primitive glBegin/glEnd methods. We went straight into VBOs because I wanted to render voxels using modern OpenGL, but we went too far because I didn't understand much about the fundamentals, such as vectors. That's been resolved and I asked what a VBO is, and he responded with an answer that I think it isn't the right one.

"It stores static vertices on the gpu", I'm not sure if this is correct, so please answer what a VBO is.

TL;DR: read the last sentence.

Thanks in advance!

\$\endgroup\$
3
\$\begingroup\$

A Vertex Buffer Object (in short VBO) is an object(buffer) that holds vertex data. It's your job, as the programmer, to fill the VBO with this data (usually Vertex positions, texture coordinates and normals) and then send it to be handled by the GPU.

This is an example of VBO initialization:

glGenBuffers( 1, &vbo ); // Generate a VBO handler
glBindBuffer( GL_ARRAY_BUFFER, vbo ); // Bind the handler
glBufferData( GL_ARRAY_BUFFER, 3 * 6 * 4 * sizeof( float), cubeVertices, GL_STATIC_DRAW );
// Allocate and initialize storage space

We're saying that we want a VBO that will store 72 floats (3 coords xyz, 6 faces, 4 vertices per face). cubeVertices is just an array of vertices (floats), and it has redundant vertice data (but don't mind that, it's just an example).

Later when you want to draw the cube you only have to bind the VBO again and draw it using a single function call. (Well, you still need a few more to bind buffers again).

By using VBOs you'll send your Vertex data only once during initialization, whereas using the deprecated functions glBegin/glEnd/glVertex you would have to send Vertex data every frame.

Back to the GL_STATIC_DRAW in my initialization example, this means that you won't be changing the buffer data later on. But you could also use GL_DYNAMIC_DRAW so that you can change vertices later. There are other flags.

However, these flags are just a hint for the GPU to decide where and how to store them. A dynamic VBO is easier / faster to update than a static one, but you can also change data on a static VBO (though you should of course use the right flag for your purposes).

For more info check: https://www.opengl.org/sdk/docs/man3/xhtml/glBufferData.xml

And also: https://www.opengl.org/sdk/docs/man3/xhtml/glBufferSubData.xml


In OpenGL 3+, you'll also use Vertex Array Objects (or VAOs) that will store multiple VBOs. These can be setup to hold the data to be sent to your own shaders, so you can even make a VBO holding vertex temperature, vertex happiness, whatever you want.

\$\endgroup\$
  • \$\begingroup\$ I have more knowledge of modern opengl now, and I have to point out vbos can store colors too, although rarely used. \$\endgroup\$ – EEVV Aug 18 '15 at 12:20
0
\$\begingroup\$

VBO's (Vertex Buffer Object) are used to upload data to the GPU (Graphic Processing Unit, in other words your graphic-card). The data does not have to be vertices, it could be used for anything. The data can also be changed later on.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.