normals for a terrain

BlitzMax Forums/BlitzMax OpenGL Programming/normals for a terrain

You can usesome code to get the nrmal from a triangle.
Since you are using quads, you have more than the required 3 points for a single face.

Just pick 3 points from the quad and generate the normal from that. The result will be the same as doing it from a quad.
It doesnt really matter which 3 points as far as I know. Just use the first 3 or so.

Also, normals are not set per vertex, but per-face. In your case a quad.

Your code can be changed from:
glBegin( GL_QUADS )
glNormal3f( nx[0],ny[0],nz[0] ) ; glTexCoord2f(0, 0) ; glVertex3f( x,y1,z )
glNormal3f( nx[1],ny[0],nz[1] ) ; glTexCoord2f(1, 0) ; glVertex3f( x+1,y2,z )
glNormal3f( nx[2],ny[0],nz[2] ) ; glTexCoord2f(1, 1) ; glVertex3f( x+1,y3,z+1 )
glNormal3f( nx[3],ny[0],nz[3] ) ; glTexCoord2f(0, 1) ; glVertex3f( x,y4,z+1 )
glEnd()


to:
glBegin( GL_QUADS )
glNormal3f( nx[0],ny[1],nz[2] )
glTexCoord2f(0, 0) ; glVertex3f( x,y1,z )
glTexCoord2f(1, 0) ; glVertex3f( x+1,y2,z )
glTexCoord2f(1, 1) ; glVertex3f( x+1,y3,z+1 )
glTexCoord2f(0, 1) ; glVertex3f( x,y4,z+1 )
glEnd()


The part between glBegin( GL_QUADS ) and glEnd()must be repeated for each polygon/quad/triangle in the mesh you are rendering.