title: Height Field with average normals
body: <p>I am creating height field and i want to create its normals (face/vertex), I am using Triangles to create a mesh. I already calculated GL quad Normals but confused here for Triangles instead of quads.
  I searched the internet and found out that two types of normals exists like per face and per vertex but not found any my code related help.
  Here is what i am doing right now to create heightfield.</p>
  <pre><code>int average_normal()
  
  { 
  glPushMatrix();
  
  
  GLfloat xdelta=xsize/xsteps;
  GLfloat zdelta=zsize/zsteps;
     
  glNormal3f(0,1,0);
  
  for (int x=0; x&lt;xsteps-1; x++)
      for (int z=0; z&lt;zsteps-1; z++)
      {
      
      glBegin(GL_TRIANGLES);
      setMaterialHeight(map[x][z]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x,map[x][z],zdelta*z);
      setMaterialHeight(map[x+1][z]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x+xdelta,map[x+1][z],zdelta*z);
      setMaterialHeight(map[x][z+1]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x,map[x][z+1],zdelta*z+zdelta);   
      glEnd();
  
      glBegin(GL_TRIANGLES);
      setMaterialHeight(map[x+1][z+1]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x+xdelta,map[x+1][z+1],zdelta*z+zdelta);  
      setMaterialHeight(map[x][z+1]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x,map[x][z+1],zdelta*z+zdelta);       
      setMaterialHeight(map[x+1][z]);
      glNormal3f(0, 0, 1);
      glVertex3f(xdelta*x+xdelta,map[x+1][z],zdelta*z);
      glEnd();
      }
  glPopMatrix();
  return true;
  }
  </code></pre>
  <p>How can I calculate its normal?</p>