PDA

View Full Version : newbie needs help on VBOs



Dylan
10-16-2006, 07:05 AM
I don't understand I do exactly as told in this tutorial:

http://www.devmaster.net/articles/oglVertexBuffer/oglVertexBuffer.php

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!

speed
10-16-2006, 09:53 AM
Did you tested if your graphic card supports this extension?

Nychold
10-16-2006, 10:03 AM
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;

Dylan
10-16-2006, 10:19 AM
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

Dylan
10-16-2006, 10:15 PM
GLuint id=0;
glGenBuffersARB(1, &amp;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?

Komat
10-16-2006, 10:28 PM
That code contains too many errors. Look at Nehe tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=45) or at example from the specification (http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt)

songho
10-17-2006, 07:07 PM
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, &amp;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 (http://songho.ca/opengl/gl_vbo.html) .