Your computer contains a CPU and a GPU. Just for simplicity, you can think that the CPU and the GPU has their own memory. In other words The GPU can’t directly access memory in your CPU and visa-versa. However, you can send data to the GPU to have it render. One way to do this is to send all your vertices on every single draw call and have the GPU do the rest. This mode of rendering was useful years ago when GPUs were not the powerful beasts they are today. It is known as immediate mode rendering.
Now a more sensical way to go about this problem is to create a place where you can save the data in the GPU, so you don’t have to send it every single frame. This memory in the GPU (or in anything in that case) is called a buffer.
Now in C and other system languages you deal with memory a lot more directly and there is no JVM and other things moving things around and doing weird stuff with your data. In Java we have another step in VBO rendering. We make a FloatBuffer, (a buffer on the CPU), and store our data inside it. Now think of your memory as a strip of paper, and the computer memory writer as the head of a printer. Now as the “printer puts data on the paper” the head moves away from the beginning of the data. We need to move the head back to the beggining of the data so that we can specify where the data starts. One call to do that is flip the other is reverse. They both work in this case (but they do have a difference in other cases).
Ok, so we have made our FloatBuffer on the CPU now we have to make our Buffer on the GPU.
This is just a simple glGenBuffers. The “handle” is like the address on the GPU where it resides.
OpenGL is a state based api. A state is like a characteristic or a variable in an object. There can only be one “state” binded to a characteristic at a time. One of these variables in OpenGL is GL_ARRAY_BUFFER, this is just characteristic that explains which VBO is currently being used at the time. You can only have one binded at the time.
So I have a buffer on my CPU and GPU, but the data is only on the CPU. I have to copy my data into the data on the GPU. So first i bind the buffer to tell OpenGL that I am going to make changes to the buffer. Next I send my data over using a glBufferData call.
Cool now i have lots of random 1s and 0s on the GPU, this isn’t that useful without explaining to the GPU what these 1s and 0s mean. This is pretty much the part where i turn my Buffer into a Vertex Buffer Object.
I use glVertexPointer, glColorPointer, etc. to explain to the GPU which 1’s and 0’s mean what. I point to which pieces of the buffer are vertices, colors, texture coords, etc.
Ok, so our VBO is set, The GPU has it’s data and an explanation of what every piece means. Now we can run a draw call (with the buffer binded) and openGL will draw whatever we want.
Remember the state things I was talking about earlier. There are a couple “client states” that openGL also has. This states simply tell OpenGL what pieces of data to use when rendering. Should it ignore the color values, or use them. ETC. If not specified it ignores it.
I think I got the majority of it.
Lots of this is metaphorical (aka. not what “actually” happens), but hopefully it will make it much easier for you to visualize.