newbie needs help on VBOs

I don’t understand I do exactly as told in this tutorial:

But my program keeps crashing on

glGenBuffersARB(1, &buffer);

I’m sure it worked before. Can anyone tell me, what header to include and what not, and what needs to be done before this statement.

it worked yesterday on a nother project, I’m doing exactly the same, i’m getting mad!

Did you tested if your graphic card supports this extension?

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;

Using that code snippet, I get the message VertexBuffer are NOT supported.

Bit weird, I have A NVIDIA Geforce 6800GT, and latest drivers installed…

NM, i fixed it, had to do with order of gl, glext and glew

	GLuint id=0;
	glGenBuffersARB(1, &id);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(colors), colors, GL_STATIC_DRAW_ARB);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, id);	
	glColorPointer(4, GL_FLOAT, 0, colors); 	 
	glVertexPointer(3, GL_FLOAT, 0, verts);
	delete[] verts;
	delete[] colors;

Question, why can’t I delete colors and verts, after sending them to the GPU?

That code contains too many errors. Look at Nehe tutorial or at example from the specification

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;

  1. glGenBuffers()
  2. glBindBuffer()
  3. 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;

Take a look at VBO note .