hi.. i asked about vertex arrays a day ago, now i can see sum polys on the screen, but its all messed up! im putting my main vertex array code here.. can anyone help me out to find whats wrong? i guess its my indices calculation, but right now i have no idea how to fix! anyone have any idea?

thanks in advance!

heres the code:

float *VertexArray;

float *IndicesArray;

int mapWidth=256;

int mapHeight=256;

void setup()

{

// vertex array: size of map * 3 (3 elements makes a vertex: x, y , z)

VertexArray = new float [mapWidth * mapHeight * 3];

// indices array: size of map * 4 (im drawing quads, so its 4 indexes to 4

vertices that makes a quad, right?)

IndexArray = new unsigned int [mapWidth * mapHeight * 4];

}

/* generate terrain's vertices&indices.. get each pixel and calculate the

height at that point and save it in the VertexArray */

void generate_landscape()

{

int index_array=0;

//

// Generate terrain's vertices

//

for(int tileZ = 0; tileZ < mapHeight; tileZ++)

{

for(int tileX = 0; tileX < mapWidth; tileX++)

{

VertexArray[index_array+0] = tileX;

VertexArray[index_array+1] = GetHeight(tileX, tileZ);

VertexArray[index_array+2] = tileZ;

index_array+=3;

}

}

//

// calculate the vertex indices so can i can use glDrawElements to draw the

terrain!

//

int index_indices=0;

for(int tileZ = 0; tileZ < mapHeight; tileZ++)

{

for(int tileX = 0; tileX < mapWidth; tileX++)

{

IndexArray[index_indices+0] = (tileZ * mapWidth) + tileX;

IndexArray[index_indices+1] = ((tileZ+1) * mapWidth) + tileX;

IndexArray[index_indices+2] = ((tileZ+1) * mapWidth) + (tileX+1);

IndexArray[index_indices+3] = (tileZ * mapWidth) + (tileX+1);

index_indices+=4;

}

}

}

/* render landscape using vertex arrays & glDrawElements() */

void render_landscape()

{

// enable vertex arrays

glEnableClientState(GL_VERTEX_ARRAY);

// feed opengl the color, vertices array & indices array

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glVertexPointer(3, GL_FLOAT, 0, Landscape.VertexArray);

glDrawElements(GL_QUADS, Landscape.mapWidth*Landscape.mapHeight*4,

GL_UNSIGNED_INT, Landscape.IndexArray);

// disable

glDisableClientState(GL_VERTEX_ARRAY);

}