Archived

This topic is now archived and is closed to further replies.

vertex arrays

Recommended Posts

trager    122
I the name Vertex Arrays banded about, wondering what are they? And how would the following be written using VA''s? this->list_base= glGenLists(1); glNewList(this->list_base, GL_COMPILE); glDisable(GL_BLEND); glColor4f(1.0,1.0,1.0,1.0); glBindTexture(GL_TEXTURE_2D, this->texture); glBegin(GL_QUADS); glTexCoord2f(0,1); glVertex2d( 0, this->img_h); glTexCoord2f(1,1); glVertex2d(this->img_w, this->img_h); glTexCoord2f(1,0); glVertex2d( this->img_w,0); glTexCoord2f(0,0); glVertex2d(0,0); glEnd(); glEndList(); thanks

Share on other sites
Enigma    1410
With immediate mode (glVertex, glTexCoord, e.t.c.) you make one or more function calls per vertex . This can get expensive if you are rendering lots of vertices. Vertex arrays are a faster method of rendering multiple vertices. Instead of sending the data for each vertex in a different function, you stick the data into the array and tell opengl to draw all the vertices.

The simple example you posted would become something like:
setup code:
static const float texCoords[8] = {0, 1, 1, 1, 1, 0, 0, 0};static const double vertices[8] = {0, img_h, img_w, img_h, img_w, 0, 0, 0};glEnableClientState(GL_VERTEX_ARRAY);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glVertexPointer(2, GL_DOUBLE, 0, vertices);glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

render code:
glDisable(GL_BLEND);glColor4f(1.0, 1.0, 1.0, 1.0);glBindTexture(GL_TEXTURE_2D, texture);glDrawArrays(GL_QUADS, 0, 4);

Haven't tried compiling that, so there may be errors. Note that in the texCoords array, the first two value are the values you speified with your first glTexCoord2f call, the next two values are the values from your second glTexCoord2f call, e.t.c.

You'll probably also want to look at: glDrawElements, interleaved arrays and vertex buffer objects.

Note that if you put vertex arrays into display lists the display list will contain the vertices that were in the vertex array when the display list was compiled, not when it is rendered, the same is true for vertex buffer objects.

Enigma

EDIT: typo

[edited by - Enigma on January 15, 2004 7:14:06 AM]

Share on other sites
trager    122
"Note that if you put vertex arrays into display lists the display list will contain the vertices that were in the vertex array when the display list was compiled, not when it is rendered, the same is true for vertex buffer objects."

Does that mean if I wan''t to change the size of the object I would have to make a new buidlist as well as changing the information in the Vertex Arrays?

Share on other sites
Enigma    1410
Yes, unless you can change your object via the modelview matrix (i.e. glScale) or a vertex program.

If you want to render dynamic data you probably don''t want to be using display lists as you will incur an overhead for compiling the display list. Streaming vertex buffer objects are probably the best option.

Enigma

Share on other sites
trager    122
Ok, I''m using very simple objects, sprites made from textured plains with occasional resizing and blending.

Is there likely to be any performance drop if I change from build lists to vertex arrays?

Share on other sites
Tree Penguin    262
The sprites where dynamic wheren''t they (so, the list would be built again every frame), if so it''s not very likely vertex arrays would be slower, unless there is a problem with the drivers you''re using.

Share on other sites
trager    122
The sprites would only be rebuilt when they needed to.

EI when they are resized or faded.

Share on other sites
Jumpman    122
you probably wouldn''t get much of a speed increase for using VA''s for just sprites.. they are ment for more complex data..