Archived

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

razialx

glVertexArray vs glVertexArrayEXT

Recommended Posts

ok, so whats the difference? i have been writing aloader for extensions that has been driving me crazy , and i find out that there is a non extension version of it? whats the deal, is this right, or am i nutz? and also, how would i go about using vertex arrays for drawing a terrain patch when the info is stored in a 2d matrix? thankx

Share this post


Link to post
Share on other sites
Vertex arrays were not a part of the original 1.0 specification, but they were available as an extension. They were made part of the core spec in 1.1. Since pretty much everything supports 1.1, you don''t have to treat it as an extension.

Share this post


Link to post
Share on other sites
ok, but how would i use vertex arrays to render terrain patches when my vertexs are stored in a matrix? is it possible?

Share this post


Link to post
Share on other sites
quote:
Original post by razialx
stored in a matrix?




huh?


To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Share this post


Link to post
Share on other sites
If you''re talking about something like rendering from a heightmap, you can''t do it directly. What I do is read in the heightmap, and use that to create a vertex array with one element for every point in the heightmap, and then create an index array into that.

Share this post


Link to post
Share on other sites
right, ok, my vertexes are stored in a 2d matrix as such
struct Vec3
{
float x,y,z;
}

then
Vec3 Map[256][256];
and the nodes for my quadtree use an x, y, halfwidth type approach to get the coordinates.
SO.
how would i use vertex arrays to render quads from this? because, i know if i set teh pointer to on row, like map[22][22], it doesn''t know to look at map[22][23] to get the other vertexs, and i don''t nkow how to use an index array, cus in a ll the whitepages, it says that the index array is for color? anyway, anything would help, especially a code snippet. thanx
Razial

Share this post


Link to post
Share on other sites
you dont need the indexarray but you need an indexarray

well.. to clarify..

you specify your array with the different parts each vector does have

glVertexArray //the position for each vertex
glNormalArray //the normal for each vertex
glIndexArray //the index to a colorarray for each vertex, used for 256-color-modes, 8bit colors with palettes
glColorArray //an array of floats wich represent colors, used for 16bit or 32bit color modes..
glTexCoordArray //texcoords for each vertex

THEN

you call glDrawElements

in drawelemtns you say what type of elements, like for example GL_TRIANGLES or GL_QUADS or something
how much
and the indexarray you want to use..

this indexarray will index into all those arrays from above to get the current vertex out..

for your heightmap it works for example like this:

#define SIZE 64

float pos[SIZE][SIZE][3];
float nrml[SIZE][SIZE][3];
float texcoord[SIZE][SIZE][2];

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,pos);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,0,nrml); //its always 3 components, so they dropped this
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,0,texcoord);


now you need indecees for your heightmap.. for every triangle you want to draw 3..

you have (SIZE-1)*(SIZE-1)*2 triangles on your heightmap resulting in (SIZE-1)*(SIZE-1)*6 indecees..

unsigned short indices[SIZE-1][SIZE-1][6];

for(int x=0;x for(int y=0;y indices[x][y][0] = x + SIZE*y;
indices[x][y][0] = (x+1) + SIZE*(y+1);
indices[x][y][0] = (x+1) + SIZE*y;
indices[x][y][0] = x + SIZE*(y+1);
indices[x][y][0] = (x+1) + SIZE*(y+1);
indices[x][y][0] = x + SIZE*y;
}
}

why exactly this?
take a shit of paper and you''ll find it out yourself

then you call

glDrawElements(GL_TRIANGLES,6*(SIZE-1)*(SIZE-1),GL_UNSIGNED_SHORT,indices);

done..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
aaahh, thank you so much, see, my problem was i was trying to use DrawArrays, not DrawELements, which can use index thingys, sweet, thanks a hella lot
Razial

Share this post


Link to post
Share on other sites