Hi All,

I am creating a chromadepth terrain using Opengl. I am loading a PGM(Portable grey map) file and then I am creating vertices for that. But I am not able to understand how would I get surface normals for the terrain? Here is my code snippet. I am using triangle strip Please help me. I am using VBO to load my buffers.
Code :
 
double getNormalizedX(unsigned long x){
	return ((double)x/((width-1)) * 2.0 - 1.0);
  }
 
  double getNormalizedY(unsigned long y){
	return ((double)(height - 1 - y) /( (height - 1))* 2.0 - 1.0);
  }
 
  double getNormalizedZ(unsigned long x,unsigned long y){
	unsigned long yPrime = (height - 1) - y;
	return   (0.25 * gridData[yPrime][x]/ (double)maxVal);	
  }
 
 void loadPGMFile(){
    FILE *pgmFile;
    char pgm_name[10000];
    size_t x,y;
    unsigned long vertexIndex = 0;
 
 
    pgmFile = fopen("sample.pgm","r");
 
    fgets(pgm_name,10000,pgmFile);
 
    fscanf(pgmFile,"%d", &width);
    fscanf(pgmFile,"%d", &height);
    fscanf(pgmFile,"%d", &maxVal);
 
    gridData = malloc(height * sizeof(int *));
 
    for( x = 0; x < height; x++){
       gridData[x] = malloc(width * sizeof(int));
         for(y = 0; y < width; y++){
            fscanf(pgmFile, "%d", &gridData[x][y]);
         }
 
    }
 
// XXX Change this allocation once everything is finished.
 
    indicesArray = malloc(width * height * 6 * sizeof(GLuint));
    verticesArray = malloc(width * height * 3 * sizeof(GLfloat));
    normalsArray = malloc(width * height * 3 * sizeof(GLfloat));
 
    int vertsI = 0, indicesI=0, normalsI = 0;
    unsigned long i=0,j=0;
    for(i = 0; i < width; i++){
      if(i > 1){
	indicesArray[indicesI++] = vertexIndex;
	indicesArray[indicesI++] = vertexIndex;
      } 
 
      for(j = 0; j < height; j++){
	verticesArray[vertsI++] = getNormalizedX(i);
	verticesArray[vertsI++] = getNormalizedY(j);
	verticesArray[vertsI++] = getNormalizedZ(i,j);
	if(i > 0){
	  indicesArray[indicesI++] = vertexIndex;
	  indicesArray[indicesI++] = vertexIndex - height;
	}
	vertexIndex++;
 
      } 
 
      if(i > 0){
	indicesArray[indicesI++] = vertexIndex - height -1;
	indicesArray[indicesI++] = vertexIndex - height -1;
      }
/**
** Trying to create Normals*
**/
    }
 
void generateTerrain(){
 static GLuint indexBuffer;
 static GLuint vertexBuffer;
    static GLuint normalsBuffer;
 
 static GLboolean first = GL_TRUE;
 
 
if(first){ 
glGenBuffers(1, &vertexBuffer);
 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
 glBufferData(GL_ARRAY_BUFFER, totalVertices * sizeof(GLfloat),
&verticesArray[0], GL_STATIC_DRAW);
 
 glGenBuffers(1, &indexBuffer);
 glBindBuffer(GL_ARRAY_BUFFER,indexBuffer);
 glBufferData(GL_ARRAY_BUFFER, totalIndices * sizeof(GLuint),
&indicesArray[0], GL_STATIC_DRAW);
first = GL_FALSE;
 
 }
 
// loadUniforms();
 glEnableVertexAttribArray(vertexPositionAttr);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(vertexPositionAttr,3, GL_FLOAT,GL_FALSE, 0, (GLvoid*) 0);
 
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
 
glDrawElements(GL_TRIANGLE_STRIP, totalIndices, GL_UNSIGNED_INT, (GLvoid*) 0);
 
 }