Vertex Buffer Objects

But now the loop range is (i think) correct and the terrain lacks a strip.

vtxdata = new GLfloat[numvtx];
	for (int z = 0; z < tsize ; z++)
		// triangle strip start...
		for (int x = 0; x < tsize ; x++)
			vtxdata[(z*tsize+x)*6]	= (GLfloat) x;
			vtxdata[((z*tsize+x)*6)+1] = (GLfloat) (hmap.GetValue(x,z)*h_scale);
			vtxdata[((z*tsize+x)*6)+2] = (GLfloat) z;
			vtxdata[((z*tsize+x)*6)+3] = (GLfloat) x;
			vtxdata[((z*tsize+x)*6)+4] = (GLfloat) (hmap.GetValue(x,z+1)*h_scale);
			vtxdata[((z*tsize+x)*6)+5] = (GLfloat) z+1;					

		// triangle strip end...*/

	for (int z=0; z < tsize; z++)
		glDrawArrays (GL_TRIANGLE_STRIP, z*tsize , tsize);

I’m not going to keep repeating myself…
Now you’ve written

for (int z = 0; z < tsize ; z++)
for (int x = 0; x < tsize ; x++)

I’m assuming you have a map of size [tsize x tsize] so if
x=tsize-1 and z=tsize-1 you will get
hmap.GetValue(tsize-1,tsize) somewhere which is out of range.
Check it over and over and over and over and over and over again.

The parameters to your drawarray calls are also incorrect. Check your indexing.


Yes, the problem was that since i’m rendering 2 vertices per heightmap point ( (x,z) and (x,z+1)) i’ve calling an incorrect number of indices in glDrawArray.

If this works, i’ll continue into multitexturing. Later i’ll apply some optimizations (no more multiple glDrawArrays calls).