DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Site Discussions > Articles Discussion
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-07-2003, 05:46 PM   #1
DmEditor
DevMaster Editor
 
Join Date: Jan 2005
Posts: 54
Default

Using OpenGL's Vertex Buffer Extension (ARB_vertex_buffer_object)
Author: Luke Philpot
Description: This short tutorial explains how to use vertex buffers in OpenGL using the the ARB_vertex_buffer_object extension. This extension provides a method of storing vertex information in direct AGP memory which could drastically improve performance.

Post your discussions/comments here by clicking on Add Reply.
DmEditor is offline   Reply With Quote
Old 07-08-2003, 11:12 AM   #2
pcvgarcia
New Member
 
Join Date: Jul 2003
Posts: 2
Default

HI,

do you know if it's possible to use multitexture with this extension? How does it works?

Thank you very much.
pcvgarcia is offline   Reply With Quote
Old 07-08-2003, 07:28 PM   #3
Luke
New Member
 
Join Date: Jan 2003
Posts: 7
Default

Should be the same as using multitexturing with normal vertex arrays.
___________________________________________
On Demand IT Solutions - http://www.odits.com.au
Luke is offline   Reply With Quote
Old 07-08-2003, 07:31 PM   #4
Luke
New Member
 
Join Date: Jan 2003
Posts: 7
Default

Hmmm, there are some bugs in the tutorial:

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1);

should be

glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer);

And I forgot how to use glDeleteBuffersARB... but I'll let you guys figure out how to do that ;7
___________________________________________
On Demand IT Solutions - http://www.odits.com.au
Luke is offline   Reply With Quote
Old 07-10-2003, 10:25 AM   #5
pcvgarcia
New Member
 
Join Date: Jul 2003
Posts: 2
Default

Hi,

here there is an example using multitexture. I hope it will be useful to somebody.

Code:
void initVBO() { int numVertex = 4; glEnable(GL_TEXTURE_2D); glGenBuffersARB(3, vboid); glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[0]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( numVertex * 3 )*sizeof(GLfloat), vertexData, GL_STATIC_DRAW_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[1]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( numVertex * 2 )*sizeof(GLfloat), textureData, GL_STATIC_DRAW_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[2]); glBufferDataARB(GL_ARRAY_BUFFER_ARB, ( numVertex * 2 )*sizeof(GLfloat), lightmapData, GL_STATIC_DRAW_ARB); } void displayVBO() { glClientActiveTextureARB(GL_TEXTURE0_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[1]); glTexCoordPointer(2,GL_FLOAT, 0, 0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glClientActiveTextureARB(GL_TEXTURE1_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[2]); glTexCoordPointer(2,GL_FLOAT, 0, 0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[0]); glVertexPointer(3,GL_FLOAT, 0, 0); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, TexManager::getTexManager().getTexture("lightmap.tga")); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, TexManager::getTexManager().getTexture("floor.tga")); glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[0]); glVertexPointer(3,GL_FLOAT, 0, 0); glDrawArrays(GL_QUADS, 0, 4 ); }

Vicenç.
vgarcia@salleurl.edu
pcvgarcia is offline   Reply With Quote
Old 07-11-2003, 08:21 AM   #6
hornet
New Member
 
hornet's Avatar
 
Join Date: Jul 2003
Posts: 2
Default

Here's an example using indexing with vertex-buffers:

Code:
//tetraeder #define V_SIZ 12 #define I_SIZ 6 GLfloat tet_verts[V_SIZ] = { \ -0.5f, -1.0f, -0.86f, \ -0.5f, -1.0f, 0.86f, \ 1.0f, -1.0f, 0.0f, \ 0.0f, 1.0f, 0.0f}; GLushort tet_index = {3, 0, 1, 2, 3, 0}; void init_buffers() { glGenBuffersARB(1, &vertex_buf); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); glBufferDataARB(GL_ARRAY_BUFFER_ARB, V_SIZ*sizeof(GLfloat), tet_verts, GL_STATIC_DRAW_ARB); //upload data glGenBuffersARB(1, &index_buf); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buf); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, I_SIZ*sizeof(GLushort), tet_index, GL_STATIC_DRAW_ARB); //upload data return; } void draw_buffers() { glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); glVertexPointer(3, GL_FLOAT, 0, 0); //3 is xyz, last 0 ("pointer") is offset in vertex-array glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buf); glEnableClientState(GL_VERTEX_ARRAY); //use indexing glDrawElements(GL_TRIANGLE_STRIP, I_SIZ, GL_UNSIGNED_SHORT, 0); //last 0 is offset in element-array return; } void deinit_buffers() { glDeleteBuffersARB(1, &vertex_buf); glDeleteBuffersARB(1, &index_buf); return; }


note to self: NO, INDEX_ARRAYS have nothing to do with vertex-indices. They are used for color-indexing :)


Regards,
\\hornet
hornet is offline   Reply With Quote
Old 07-11-2003, 09:12 AM   #7
hornet
New Member
 
hornet's Avatar
 
Join Date: Jul 2003
Posts: 2
Red face

...and a version using mapping instead

Code:
void init_buffers_map() { glGenBuffersARB(1, &vertex_buf); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buf); glBufferDataARB(GL_ARRAY_BUFFER_ARB, V_SIZ*sizeof(GLfloat), 0, GL_STREAM_DRAW_ARB); //allocate memory on board float* p1 = (float*)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); for(int i=0; i<V_SIZ; i++) p1[i] = tet_verts[i]; //upload vertex-data glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); //invalidates p1 glGenBuffersARB(1, &index_buf); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buf); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, I_SIZ*sizeof(GLushort), 0, GL_STREAM_DRAW_ARB); //allocate memory on board GLushort* p2 = (GLushort*)glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get pointer to memory on board for(int i=0; i<I_SIZ; i++) p2[i] = tet_index[i]; //upload indices glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); return; }

Note: There is no reason you shouldn't map both buffers at the same time - I just do it this way for simplicity.


\\hornet
hornet is offline   Reply With Quote
Old 09-02-2003, 12:41 PM   #8
Vifani
New Member
 
Join Date: Sep 2003
Posts: 22
Default

Vertex Buffers modify input data.

Code:
glGenBuffersARB(1, &oggetto->vertexbuffer); glBindBufferARB(GL_ARRAY_BUFFER_ARB, oggetto->vertexbuffer); glBufferDataARB(GL_ARRAY_BUFFER_ARB, oggetto->numOfVerts*3*sizeof(GLfloat), oggetto->pVerts, GL_STATIC_DRAW_ARB);

After this code, object verticies change !

I have tried to use vertex array without and with this code and I have seen different results.

Can anyone help me ?

When I use vertex array with indicies, I have no problem. With vertex buffer all polygons are worst.
Vifani is offline   Reply With Quote
Old 09-02-2003, 12:46 PM   #9
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

could you post the code where you draw the vertices including the glVertexPointer calls, etc. ?
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 09-02-2003, 12:52 PM   #10
Vifani
New Member
 
Join Date: Sep 2003
Posts: 22
Default

Now, I have solved the previous problem, but is it possible that I have more fps with vertex array ?
Vifani is offline   Reply With Quote
Old 10-08-2003, 08:36 AM   #11
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Angry

Hello

I've been messing with VBO's

First I use VBO to render the static scene data.
Second I try using normal vertex arrays for the dynamic objects.

But they don't show
When I use glDeleteBuffersARB before using my normal vertex arrays, then they do render just fine....

Is there a way to make them show up without having to call glDeleteBuffers for every frame ? This is a huge performance drop of course
Isn't there something like glUnBufferARB ???

Thanks.
Kris.
Asshen is offline   Reply With Quote
Old 10-08-2003, 09:08 AM   #12
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

do you map your buffers for writing ? i'm not sure wether that could somehow influence vertex array behaviour. why would you want to mix the two in the first place ??? in combination with vertex programs you should be able to elimnate the need for storing vertex data in application memory most of the time. i don't know anything about what you are doing so i'm just giving hints
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 10-08-2003, 09:11 AM   #13
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Default

Here it is
I'm using normal vertex arrays for the dynamic data.
But I will probably change it, now that I think of it, I could use VBO for those too

Code:
void CKGLLevel::RenderLevelVBO(void) { if(!VBOactive) GenerateVBO(); EnableArrays(); //vertex buffer glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbuffer); glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0)); //normal buffer glBindBufferARB(GL_ARRAY_BUFFER_ARB, nbuffer); glNormalPointer(GL_FLOAT, 0, BUFFER_OFFSET(0)); //texcoord buffer glBindBufferARB(GL_ARRAY_BUFFER_ARB, tbuffer); glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(0)); //draw it damnit :p for(int h=0; h<QT_Height; h++) { for(int w=0; w<QT_Width; w++) { meshCursor = QT[w][h].Start; while(meshCursor->next) { meshCursor=meshCursor->next; TexDB->BindTexture(meshCursor->TexID); glDrawElements(GL_TRIANGLES, meshCursor->IAsize, GL_UNSIGNED_INT, meshCursor->IA); } } } //draw dynamic objects for(h=0; h<QT_Height; h++) { for(int w=0; w<QT_Width; w++) { dynObjIDCursor = QT[w][h].DynObjIDs; while(dynObjIDCursor->next) { dynObjIDCursor = dynObjIDCursor->next; RenderDynObj(dynObjIDCursor->ID); } } } DisableArrays(); } void CKGLLevel::RenderDynObj(int ID) { dynObjCursor = DynObjects; while(dynObjCursor->next) { dynObjCursor = dynObjCursor->next; if(dynObjCursor->ID == ID) { glPushMatrix(); glTranslatef(dynObjCursor->translation[0],dynObjCursor->translation[1],dynObjCursor->translation[2]); //texture TexDB->BindTexture(dynObjCursor->TexID); //if(!glIsEnabled(GL_VERTEX_ARRAY)) {Message("Arrays not enabled");exit(0);} //texcoord buffer glTexCoordPointer(2, GL_FLOAT, 0, dynObjCursor->TexcData); //normal buffer glNormalPointer(GL_FLOAT, 0, dynObjCursor->NormData); //vertex buffer glVertexPointer(3, GL_FLOAT, 0, dynObjCursor->VertData); //draw glDrawArrays(GL_TRIANGLES, 0, dynObjCursor->amount); /* int nv=0; int t=0; glBegin(GL_TRIANGLES); for(int i=0; i<dynObjCursor->amount;i++) { glTexCoord2f(dynObjCursor->TexcData[t+0], dynObjCursor->TexcData[t+1]); t+=2; glNormal3f( dynObjCursor->NormData[nv+0], dynObjCursor->NormData[nv+1], dynObjCursor->NormData[nv+2] ); glVertex3f( dynObjCursor->VertData[nv+0], dynObjCursor->VertData[nv+1], dynObjCursor->VertData[nv+2] ); nv+=3; } glEnd(); */ glPopMatrix(); } } }
Asshen is offline   Reply With Quote
Old 10-08-2003, 09:54 AM   #14
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Unhappy

Well, after all, it probably isn't possible to use VBO for the dynamic data...

What penalty comes with uploading the data to the video memory ?
Anybody knows ?

I would have to upload new data almost every frame because I'm also using animated characters in the application.

So, I'm still looking for an answer to my initial question

Greetz.
K
Asshen is offline   Reply With Quote
Old 10-08-2003, 10:44 AM   #15
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

well, you upload it every frame anyway then... either way, VBOs or vertex arrays

you have seperate buffers for vertices, normals, etc. ????????
that's not necessary at all. just use one buffer for all of them

if you want i'll send you my implementation ( in D though )
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 10-08-2003, 10:45 AM   #16
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Default

Somebody on OpenGL.org forum gave me a solution (simple actually):
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

Hehe

Oh, yes, I know I can use only 1 arrays and then use the offset, but I prefer keeping data separated

PS: What is D ? New language ?
PPS: Yes, show me your implementation, I'm always happy to learn new stuff

Kris
Asshen is offline   Reply With Quote
Old 10-08-2003, 10:47 AM   #17
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

well, i guess you could do it that way
yeah, i will send it your way.
as to D. yep it's a new language.
check it out.

i think your email address might be hidden...
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 10-08-2003, 12:04 PM   #18
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Default

email= AsshenArgon@hotmail.com (not used for MSN)

I've taken a look at D
Looks cool, but for now I'll stick to Visual C++.

Does there exists a graphical interface (like visual studio) for D ?

K
Asshen is offline   Reply With Quote
Old 10-08-2003, 12:11 PM   #19
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

there is one in development called DIDE but i think it would be no problem to integrate the D compiler into vs.net if you wanted to. i'll send you the code. i even found an old c++ version. might be more useful for you...
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 10-09-2003, 12:23 AM   #20
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Default

Thank you very much
Asshen is offline   Reply With Quote
Old 10-09-2003, 03:04 AM   #21
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

sorry that i didn't send it to you. you probably won't see it before friday night because i'm away till then. i will .rar it up as soon as i get back
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 10-09-2003, 02:20 PM   #22
Asshen
New Member
 
Join Date: Sep 2003
Posts: 15
Default

No problem
I'm still experimenting anyway.

I'm coding a little game (who isn't huh), and just figuring out which approach is faster for my specific needs

K
Asshen is offline   Reply With Quote
Old 08-26-2004, 01:02 AM   #23
Jackylam
New Member
 
Join Date: Aug 2004
Posts: 2
Default

When I try
Code:
glClientActiveTextureARB(GL_TEXTURE1_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboid[1]); glTexCoordPointer(3,GL_FLOAT, 0, 0); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
it has error when I add glClientActiveTextureARB(GL_TEXTURE1_ARB);
I want to know what the problem is.

Thank you
Jackylam is offline   Reply With Quote
Old 08-26-2004, 05:53 AM   #24
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

what is the error message ?
what is the error ?
be more specific
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 08-29-2004, 02:00 AM   #25
Jackylam
New Member
 
Join Date: Aug 2004
Posts: 2
Default

Quote:
Originally Posted by anubis
what is the error message ?
what is the error ?
be more specific
[snapback]9693[/snapback]

it's memory problem and I solve it. Thanks.
But, I met another problem. It is Color array problem

how can I update the color array regularly when I pushed the color array into
GPU memory at vert begining. For example, I use
Code:
glEnableClientState(GL_COLOR_ARRAY); glGenBuffersARB(1, &colorarrayid); glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorarrayid); glBufferDataARB(GL_ARRAY_BUFFER_ARB, W, H, colorptr, GL_DYNAMIC_DRAW_ARB);
to initialize the color buffer at GPU.

If I update the content of colorptr, how can I refresh the GPU memory which is
allocated for colorptr?

Can I use:
Code:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, colorarrayid); glBufferDataARB(GL_ARRAY_BUFFER_ARB, W, H, colorptr, GL_DYNAMIC_DRAW_ARB);

Thank you
Jackylam is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 09:02 PM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.