I need help on setting up VBO's in my code

Started by
47 comments, last by MARS_999 20 years, 7 months ago
I have looked all over the net for a good tutorial on how to use "GL_ARB_vertex_buffer_object" as an extension and haven''t found one. I have a Radeon 9700. I would appreciate any help on find a good tutorial or some example code. Thanks
Advertisement
Try this:
http://www.devmaster.net/articles/oglVertexBuffer/oglVertexBuffer.php

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
hm... isnt it sad when this ( http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_buffer_object.txt ) will not just explain them a lot better but also offer about 4 times as many examples?
f@dzhttp://festini.device-zero.de
Yeah, don''t bother with tutorials... just read the extension spec. You''ll get a much better feel for VBOs.

How appropriate. You fight like a cow.
Ok I am assuming this because it says arrays that I can use 3D arrays with VBO's.
float terrain[y][x][z];   struct Vertex	{	float x;	float y;	float z;	};	Vertex terrain[MAP_Z][MAP_X];


Can I use multi-dimension arrays with VBO's?
Will their be any performance decrease for 3D arrays? I am also assuming I can't send a array of structures?

[edited by - Mars_999 on August 7, 2003 3:58:16 PM]
Anyone? Anyone? Here using VBO''s this way? Is it even allowed? Or does the buffer have to be a float array[]. Thanks
Ok, I got the code up and running for VBO's. I am using vertex arrays and trying to use VBO's also and my FPS drop about 80fps!!! What gives? Don't you have to use vertex arrays first before you can use VBO's? Here is my code.

//init functino	glGenBuffersARB(1, &vertex_buffer);	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buffer);	glBufferDataARB(GL_ARRAY_BUFFER_ARB, (sizeof(float) * 3) * MAP_Z * MAP_X, terrain, GL_STATIC_DRAW_ARB);	glGenBuffersARB(1, &indices_buffer);	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer);	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, (sizeof(unsigned int) * 2) * MAP_Z * MAP_X, indices, GL_STATIC_DRAW_ARB);//draw function	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buffer);	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer);	for(int z = 0; z < MAP_Z - 1; z++)		glDrawElements(GL_TRIANGLE_STRIP, MAP_X * 2, GL_UNSIGNED_INT, &indices[z * MAP_X * 2]);//and of course I have deleted the buffers also


What is wrong with my code? I get a atioglxx.dll access violation error if I remember right. Do I need to setup my arrays with dynamic memory? Thanks

[edited by - Mars_999 on August 16, 2003 11:59:04 PM]
somehow im missing a call to glvertexpointer. also i trust your indices are all below 65xxx and with deleting the buffers you mean deleting them when you close the app.
f@dzhttp://festini.device-zero.de
Don''t call GenBuffers every single time you render. Do it once at initialization, and then for rendering all you have to do is bind your buffers and call DrawElements.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
quote:Original post by Trienco
somehow im missing a call to glvertexpointer. also i trust your indices are all below 65xxx and with deleting the buffers you mean deleting them when you close the app.


Do I need to call glVertexPointer() everytime in my rendering function? I call it in my initialization function. And no my indices isn't below 65k its 132k so what am I to do about that? My vertex array isn't either.

struct Vertex
{
float x,y,z;
};
Vertex terrain[256][256] = {0};
thats 65k elements and 786k bytes right?
and
indices is
unsigned int indices[MAP_Z * MAP_X * 2];
thats 256*256*2 = 131k elements or 524k bytes right?

So my indices would have to be reduced to 65k how is that going to work? Could I make the indices like my Vertex struct using two floats such as
struct Vertex2
{
unsigned int x;
unsigned int y;
};

Vertex2 indices[256][256] = {0};

or not?

Also I get the error on this line??
glDrawElements(GL_TRIANGLE_STRIP, MAP_X * 2, GL_UNSIGNED_INT, &indices[z * MAP_X * 2]);


[edited by - Mars_999 on August 17, 2003 8:58:40 PM]

This topic is closed to new replies.

Advertisement