At going through all the posts wriiten by dimebolt and dhk since my last constribution to this thread, there are two things that I've noticed:
(1) If you access a 2D defined array with a 1D index, then you have to know that the first index has the highest priority. So
int array[2][2];array[0][0] = 0;array[0][1] = 1;array[1][0] = 2;array[1][1] = 3;for(int index=0;index<3;++index) printf("%d\n",((int*)array)[index]);
results in the sequence 0123 !
However, if you define a 1D array, and access it w/ a 2D index, then you may use either [x+y*x_size] or [y+x*y_size] w/ 0<=x<x_size, 0<=y<y_size. Which you choose play no role, but always use the same!
(2) The trn array is filled up linearly, say a vertex in trn[0], the next in trn[1], and so on, with an index dependency like this:
x,z=0,0 . x,z=1,0 . x,z=2,0 ... x,z=0,1 . x,z=1,1 . x,z=2,1 ... x,z=0,2 ...
So, when wrapping around at the limit of x == SIZE-1, one gets
x,z=0,0 . x,z=1,0 . x,z=2,0 ...
x,z=0,1 . x,z=1,1 . x,z=2,1 ...
x,z=0,2 . x,z=1,2 . x,z=2,2 ...
As a 1D index, the arrangement is (just that x+z*SIZE)
0 . 1 . 2 ...
SIZE+0 . SIZE+1 . SIZE+2 ...
2*SIZE+0 . 2*SIZE+1 . 2*SIZE+2 ...
When rendering, neighboured vertices have to be used to build up a tri. Since your glBegin uses GL_TRIANGLES, the indices for the first tri have to be {0,1,SIZE+0}, and for the second tri {1,SIZE+1,SIZE+0}.
If you still want to go with an incrementing index in your rendering routine, you should do something like this:
for(int i=0;i<(SIZE-1)*(SIZE-1);++i) { glNormal3f ( normals.x, normals.y, normals.z ); glTexCoord2f ( 0.0f, 0.0f ); if((i&1)==0) { glVertex3f ( trn.x, trn.y, trn.z ); glVertex3f ( trn[i+1].x, trn[i+1].y, trn[i+1].z ); glVertex3f ( trn[i+SIZE].x, trn[i+SIZE].y, trn[i+SIZE].z ); } else { glVertex3f ( trn[i+1].x, trn[i+1].y, trn[i+1].z ); glVertex3f ( trn[i+SIZE+1].x, trn[i+SIZE+1].y, trn[i+SIZE+1].z ); glVertex3f ( trn[i+SIZE].x, trn[i+SIZE].y, trn[i+SIZE].z ); }}
This is, in fact, not optimal, but hopefully shows the dependency between the index calculations I mean. If I made no mistakes, then index i iterates the upper left corner of quads of your terrain, and the quad is rendered as two opposite tris.
I recommend to use tri-strips instead of particular tris, since it would make the rendering routine much more effective _and_ simpler.
BTW: Nice indexing problem ;-)