Something else which throws people off is, you can’t load extensions, even using WGL, until you’ve created and loaded an OpenGL context. More than likely, though, speed is right. There’s no mention of using the extension string (glGetString(GL_EXTENSIONS)) to see if GL_ARB_vertex_buffer exists, nor is there even a simple check, like:
if (glGenBuffersARB==0)
cout << "Vertex Buffers NOT supported!" << endl;
Originally posted by Dylan: Question, why can’t I delete colors and verts, after sending them to the GPU?
You need to bind (hook) the VBO before copying data. The order of VBO initialization looks like;
glGenBuffers()
glBindBuffer()
glBufferData()
Notice that the last param of glColorPointer() and glVertexPointer() is now the starting offset in VBO, NOT actual memory addresses (pointers). Therefore, if vertex (or colour) data are stored at the beginning of VBO, then it would be 0.
If you want to have a single VBO to store both vertices and colours, the size of VBO would be sizeof(verts)+ sizeof(colors). In other way, you can create 2 VBOs to store vertices and colours separately.
Here is an example to store both vertice and colours in one VBO;
...
// create a VBO
GLuint vboId;
glGenBuffers(1, &vboId);
// hook the created VBO
glBindBuffer(GL_ARRAY_BUFFER, vboId);
// reserve buffer space with NULL pointer
glBufferData(GL_ARRAY_BUFFER, sizeof(verts)+sizeof(colors), NULL, GL_STATIC_DRAW);
// first, copy vertex data with glBufferSubData()
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(verts), verts);
// second, copy colours (Notice the offset)
glBufferSubData(GL_ARRAY_BUFFER, sizeof(verts), sizeof(colors), colors);
// it is safe now to delete local arrays
delete [] verts;
delete [] colors;
...