PDA

View Full Version : compiled vertex arrays & glDrawElements



worm
12-11-2000, 06:28 AM
hi there!
im trying to get my heightmap to be rendered with vertex arrays, using glDrawElements..
well my problem is that everything is ok, except the terrain doesnt show up with i do this code..
well im new to this here, so i dunno what can be wrong...

VertexArray is an array of floats: [Landscape.mapWidth * Landscape.mapHeight * 3];
IndexArray is an array of unsigned ints: [Landscape.mapWidth * Landscape.mapHeight * 3 * 2];
(this holds the indices of the 2 triangles that makes each tile in the terrain)

well anyone have any idea? i've seen some code around on this, but didnt help much..
this might have sum stupid code, but well im trying this without any info.. cant find any that tells me what these funcs really do


glEnableClientState(GL_VERTEX_ARRAY);

glLockArraysEXT(0, Landscape.mapWidth * Landscape.mapHeight * 2); // lock vertex arrays

glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_FOG);
glColor4f(1,1,1,1);
glVertexPointer(3, GL_FLOAT, 0, Landscape.VertexArray);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, Landscape.IndexArray);
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_FOG);

glUnlockArraysEXT(); // unlock vertex arrays

glDisableClientState(GL_VERTEX_ARRAY);

zed
12-11-2000, 10:09 AM
first get it working without locked arrays (btw locking them will prolly give no speed increase)

glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, Landscape.IndexArray);

here youre only drawing 4 elements i assume u want to draw much more then that

DFrey
12-11-2000, 10:22 AM
Also when using compiled vertex arrays, you generally set the vertex pointer before locking the arrays. And uh yep, I doubt in this circumstance you'll get much of any benefit using compiled vertex arrays. You'd likely only see significant benefits if you were drawing very many elements and were using multipass texturing.