Index: branches/height_map_merge/src/lib/graphics/importer/height_map.cc
===================================================================
--- branches/height_map_merge/src/lib/graphics/importer/height_map.cc	(revision 6540)
+++ branches/height_map_merge/src/lib/graphics/importer/height_map.cc	(revision 6579)
@@ -30,5 +30,5 @@
 #endif
 
-Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm )
+Tile::Tile(int i1, int j1, int i2, int j2, HeightMap* hm ) 
 {
 
@@ -37,6 +37,6 @@
 lowResModel  = new VertexArrayModel();
 
-this->load(i1,j1,i2,j2,hm,highResModel,4);
-this->load(i1,j1,i2,j2,hm,lowResModel, 32);
+this->load(i1,j1,i2,j2,hm,highResModel,2);
+this->load(i1,j1,i2,j2,hm,lowResModel, 8);
 }
 
@@ -54,5 +54,5 @@
 void Tile::draw()
 {
- lowResModel->draw();
+ lowResModel->draw(); 
 }
 
@@ -71,219 +71,237 @@
 void Tile::load(int i1, int j1, int i2, int j2, HeightMap* hm, VertexArrayModel* model, int Res)
 {
-
-        #define heightMap hm->heightMap
-        #define colours   hm->colours
-        #define scaleX hm->scaleX
-        #define scaleY hm->scaleY
-        #define scaleZ hm->scaleZ
-        #define shiftX hm->shiftX
-        #define shiftY hm->shiftY
-        #define shiftZ hm->shiftZ
-        #define normalVectorField hm->normalVectorField
-
-        int sampleRate = Res;
-
-        unsigned char height = 0;
-        int offset = 0;
-
-        float r = 0.0;
-        float g = 0.0;
-        float b = 0.0;
-
-
+	
+	#define heightMap hm->heightMap
+	#define colours   hm->colours
+	#define scaleX hm->scaleX
+	#define scaleY hm->scaleY
+	#define scaleZ hm->scaleZ
+	#define shiftX hm->shiftX
+	#define shiftY hm->shiftY
+	#define shiftZ hm->shiftZ
+	#define normalVectorField hm->normalVectorField
+	
+	int sampleRate = Res;
+	
+	 float height = 0;
+ 	int offset = 0;
+ 	
+	float r = 0.0;
+	float g = 0.0;
+	float b = 0.0;
+
+ 
 PRINTF(0)("loadin * \n");
-
+ 
  if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
-
-        SDL_LockSurface(heightMap);
-
-        for(int i = i1 ; i <= i2  ; i +=sampleRate)
-        {
-                int w = 0;
-
-
-
-                 if(hm->hasColourMap)
-                 {
-                 r = (float)colours[3*w+2 + 3*i*(heightMap->w )];
-                 g = (float)colours[3*w+1 + 3*i*(heightMap->w)];
-                 b = (float)colours[3*w+0 + 3*i*(heightMap->w)];
-                 }
-
-                w = j1;
-                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
-                model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-            for(int j = j1  ; j <= j2    ;  j += sampleRate)
-            {
-
-
-                 // To be fixed
-                 if(hm->hasColourMap)
-                 {
-                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
-                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
-                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
-                 }
-                height =  hm->heights[j+sampleRate + i*(heightMap->w )];
-                model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
-
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-
-                w = j;
-            }
-
-
-                model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
-                model->addTexCoor((((w+sampleRate)/sampleRate)%4)/4.0,(((i+ sampleRate)/sampleRate)%4)/4.0);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-        }
-
-
-
-
-
-        SDL_UnlockSurface(heightMap);
-        int cnt = 0;
-        for(int i = i1   ; i < i2  ; i +=sampleRate)
-        {
-
-            for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
-            {
-
-                model->addIndice(cnt);
-                model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
-                cnt++;
-
-            }
-
-
-
-                 model->newStripe();
-
-
-        }
-         cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
-
-                for(int j = j1 ; j <= j2    ;  j += sampleRate)
-            {
-                int i = i1;
-
-                 // To be fixed
-                 if(hm->hasColourMap)
-                 {
-                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
-                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
-                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
-                 }
-
-                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i - sampleRate)/sampleRate)%texRate)/texRatef);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-            }
-
-                for(int j = j1  ; j <= j2    ;  j += sampleRate)
-            {
-                int i = i1;
-                height =  hm->heights[j+sampleRate + i*(heightMap->w )];
-                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i)/sampleRate)%texRate)/texRatef);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-            }
-
-
-
-            for(int j = j1  ; j <= j2    ;  j += sampleRate)
-            {
-                int i = i2;
-
-                 // To be fixed
-                 if(hm->hasColourMap)
-                 {
-                 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
-                 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
-                 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
-                 }
-
-                model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-            }
-
-
-            for(int j = j1 ; j <= j2    ;  j += sampleRate)
-            {
-                int i = i2;
-                height =  hm->heights[j+sampleRate + i*(heightMap->w )];
-                model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right
-                model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-                model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
-                model->addColor(r/255.0,g/255.0,b/255.0);
-
-            }
-
-
-
-
-         // link Boarder Stripe
-            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
-            {
-
-                model->addIndice(cnt);
-                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
-                cnt++;
-
-            }
-
-                cnt++;
-
-                 model->newStripe();
-
-
-
-
-
-         cnt += (j2-j1)/ sampleRate;
-
-        // link 2nd BoarderStripe
-            for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
-            {
-
-                model->addIndice(cnt);
-                model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
-                cnt++;
-
-            }
-
-
-
-         model->finalize();
-
-
-
-
-        #undef heightMap
-        #undef colours
-        #undef scaleX
-        #undef scaleY
-        #undef scaleZ
-        #undef shiftX
-        #undef shiftY
-        #undef shiftZ
-        #undef normalVectorField
-
+	
+	SDL_LockSurface(heightMap);
+
+	for(int i = i1 ; i <= i2  ; i +=sampleRate)
+	{
+		int w = 0;
+
+		
+		
+		 if(hm->hasColourMap)
+		 {
+		 r = (float)colours[3*w+2 + 3*i*(heightMap->w )];
+		 g = (float)colours[3*w+1 + 3*i*(heightMap->w)];
+		 b = (float)colours[3*w+0 + 3*i*(heightMap->w)];
+		 }
+		
+		w = j1;
+	    	model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
+		model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
+		model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);
+		
+	    for(int j = j1  ; j <= j2    ;  j += sampleRate)
+	    {
+	    
+	    
+	    	 // To be fixed
+		 if(hm->hasColourMap)
+		 {
+		 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
+		 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
+		 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
+		 }
+		height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
+		height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
+		height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
+		
+		height=height/5.0;
+		
+		model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right	
+		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
+		model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
+		
+		//PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
+		
+ 		model->addColor(r/255.0,g/255.0,b/255.0);
+		w = j;
+	    }
+		
+		
+		model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
+		model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
+		model->addTexCoor((((w+sampleRate)/sampleRate))/4.0,(((i+ sampleRate)/sampleRate))/4.0);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);
+		
+	}
+	
+	
+	
+
+
+	SDL_UnlockSurface(heightMap);
+	int cnt = 0;
+	for(int i = i1   ; i < i2  ; i +=sampleRate)
+	{
+		
+	    for(int j = j1-sampleRate  ; j < j2  + 2*sampleRate  ;  j += sampleRate)
+	    {
+		
+	    	model->addIndice(cnt);
+		model->addIndice(cnt  + (j2 -j1 + 3* sampleRate  )/ sampleRate );
+		cnt++;
+		
+	    }
+	    	
+	    	
+	    	
+		 model->newStripe();	
+		
+		
+	}
+	 cnt += (j2 -j1 + 3* sampleRate)/ sampleRate;
+	
+		for(int j = j1 ; j <= j2    ;  j += sampleRate)
+	    {
+	    	int i = i1;
+	    
+	    	 // To be fixed
+		 if(hm->hasColourMap)
+		 {
+		 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
+		 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
+		 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
+		 }
+		
+		model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right	
+		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
+		model->addTexCoor(((j/sampleRate))/texRatef,(((i - sampleRate)/sampleRate))/texRatef);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);		
+	
+	    }
+
+	        for(int j = j1  ; j <= j2    ;  j += sampleRate)
+	    {
+	    	int i = i1;
+	    	height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
+		height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
+		height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
+		height=height/5.0;
+		
+		model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right	
+		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
+		model->addTexCoor(((j/sampleRate))/texRatef,(((i)/sampleRate))/texRatef);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);
+	    
+	    }
+	    
+	        
+	    
+	    for(int j = j1  ; j <= j2    ;  j += sampleRate)
+	    {
+	    	int i = i2;
+	    
+	    	 // To be fixed
+		 if(hm->hasColourMap)
+		 {
+		 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
+		 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
+		 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
+		 }
+		
+		model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right	
+		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
+		model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);		
+	
+	    }
+	    	    
+	    
+	    for(int j = j1 ; j <= j2    ;  j += sampleRate)
+	    {
+	    	int i = i2;
+	    		height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
+		height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
+		height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
+		height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
+		height=height/5.0;
+		model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right	
+		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
+		model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
+ 		model->addColor(r/255.0,g/255.0,b/255.0);
+	    
+	    }
+	   
+
+	
+	
+	 // link Boarder Stripe
+	    for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
+	    {
+		
+	    	model->addIndice(cnt);
+		model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
+		cnt++;
+		
+	    }
+	    	
+	    	cnt++;
+	    	
+		 model->newStripe();	
+		
+		
+	
+	
+	
+	 cnt += (j2-j1)/ sampleRate;
+	
+	// link 2nd BoarderStripe
+	    for(int j = j1-sampleRate  ; j < j2    ;  j += sampleRate)
+	    {
+		
+	    	model->addIndice(cnt);
+		model->addIndice(cnt  + (j2 -j1 +  sampleRate  )/ sampleRate );
+		cnt++;
+		
+	    }
+	 
+	    
+	
+	 model->finalize();
+	 
+	 
+	 
+	 
+	#undef heightMap 
+	#undef colours   
+	#undef scaleX 
+	#undef scaleY 
+	#undef scaleZ 
+	#undef shiftX 
+	#undef shiftY 
+	#undef shiftZ 
+	#undef normalVectorField 
+	 
 }
 
@@ -299,18 +317,18 @@
    if(heightMap!=NULL) {
 
-                 PRINTF(0)("loading Image %s\n", height_map_name);
-                 PRINTF(0)("width : %i\n", heightMap->w);
-                 PRINTF(0)("height : %i\n", heightMap->h);
-                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
-                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
-                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
-                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
-                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
-                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
-                }
+		 PRINTF(0)("loading Image %s\n", height_map_name);
+		 PRINTF(0)("width : %i\n", heightMap->w);
+		 PRINTF(0)("height : %i\n", heightMap->h);
+		 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
+		 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
+		 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
+		 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
+		 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
+		 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
+		}
 
      else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
 
-
+	
   generateNormalVectorField();
 
@@ -328,14 +346,14 @@
    if(heightMap!=NULL) {
 
-                 PRINTF(0)("loading Image %s\n", height_map_name);
-                 PRINTF(0)("width : %i\n", heightMap->w);
-                 PRINTF(0)("height : %i\n", heightMap->h);
-                 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
-                 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
-                 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
-                 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
-                 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
-                 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
-                }
+		 PRINTF(0)("loading Image %s\n", height_map_name);
+		 PRINTF(0)("width : %i\n", heightMap->w);
+		 PRINTF(0)("height : %i\n", heightMap->h);
+		 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
+		 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
+		 PRINTF(0)("Bshift: %i\n", heightMap->format->Bshift);
+		 PRINTF(0)("Gshift: %i\n", heightMap->format->Gshift);
+		 PRINTF(0)("Rmask: %i\n", heightMap->format->Rmask);
+		 PRINTF(0)("Gmask: %i\n", heightMap->format->Gmask);
+		}
 
      else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
@@ -349,20 +367,21 @@
   colourMap = IMG_Load(colour_map_name);
   }
+  
   if(colourMap != NULL)
-                {
-                 PRINTF(0)("loading Image %s\n", colour_map_name);
-                 PRINTF(0)("width : %i\n", colourMap->w);
-                 PRINTF(0)("height : %i\n", colourMap->h);
-                 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
-                 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
-                 PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
-                 PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
-                 PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
-                 PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
-                 }
-                 else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
-
-
-
+  		{
+  		 PRINTF(0)("loading Image %s\n", colour_map_name);
+		 PRINTF(0)("width : %i\n", colourMap->w);
+		 PRINTF(0)("height : %i\n", colourMap->h);
+		 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
+		 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
+		 PRINTF(0)("Bshift: %i\n", colourMap->format->Bshift);
+		 PRINTF(0)("Gshift: %i\n", colourMap->format->Gshift);
+		 PRINTF(0)("Rmask: %i\n", colourMap->format->Rmask);
+		 PRINTF(0)("Gmask: %i\n", colourMap->format->Gmask);
+		 }
+		 else       PRINTF(0)("oops! couldn't load colorMap for some reason.\n");
+
+		 
+		   
   if(colourMap != NULL)
   {
@@ -371,7 +390,7 @@
   }
   else hasColourMap = false;
-
-
-   heights  = (unsigned char*) heightMap->pixels;
+  
+	
+  heights  = (unsigned char*) heightMap->pixels;
 
 
@@ -379,5 +398,5 @@
 HeightMap::~HeightMap()
 {
-        delete heightMap;
+	delete heightMap;
 }
 
@@ -393,15 +412,15 @@
 for(int i = 0; i < (heightMap->h - tileSize )/ tileSize; i ++)
 {
-        for(int j = 0; j < (heightMap->w - tileSize )/ tileSize; j ++)
-        {
-
-         tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
-        }
-}
-
-}
-
-
-void HeightMap::draw()
+	for(int j = 0; j < (heightMap->w - tileSize )/ tileSize; j ++)
+	{
+	 
+	 tiles[i][j] =    new Tile( i*tileSize ,  j*tileSize , (i+1)*tileSize, (j+1)*tileSize , this ) ;
+	}
+}
+
+}
+
+
+void HeightMap::draw() 
 {
 const PNode* camera = State::getCamera();
@@ -409,9 +428,9 @@
 
 int i_min = 1;
-int i_max = (heightMap->h - tileSize)/ tileSize;
+int i_max = (heightMap->h - tileSize )/ tileSize;
 int j_min = 1;
 int j_max= (heightMap->w - tileSize) / tileSize;
 
-// calc i_min , i_max j_min and j_maxt
+// calc i_min , i_max j_min and j_maxt 
 
 int centerX =  (int)((heightMap->h - ((v.x - shiftX)/ (float)scaleX ))/ tileSize);
@@ -426,28 +445,28 @@
 
 
-for(int i = 1; i <  i_min        ; i ++)
-{
-        for(int j = 1; j < j_max ; j++)
-        {
-
-         tiles[i][j]->drawLowRes();
-        }
-}
-for(int i = i_min; i <  i_max    ; i ++)
-{
-        for(int j = j_min; j < j_max ; j++)
-        {
-
-         tiles[i][j]->drawHighRes();
-        }
-}
-
-for(int i = i_max; i <  (heightMap->h -tileSize)/tileSize        ; i ++)
-{
-        for(int j = 1; j < j_max ; j++)
-        {
-
-         tiles[i][j]->drawLowRes();
-        }
+for(int i = 1; i <  i_min	 ; i ++)
+{
+	for(int j = 1; j < j_max ; j++)
+	{
+	 	
+	 tiles[i][j]->drawLowRes();
+	}	
+} 
+for(int i = i_min; i <  i_max	 ; i ++)
+{
+	for(int j = j_min; j < j_max ; j++)
+	{
+	 	
+	 tiles[i][j]->drawHighRes();
+	}	
+}
+
+for(int i = i_max; i <  (heightMap->h -tileSize)/tileSize	 ; i ++)
+{
+	for(int j = 1; j < j_max ; j++)
+	{
+	 	
+	 tiles[i][j]->drawLowRes();
+	}	
 }
 
@@ -455,15 +474,15 @@
 for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++ )
 {
-        for(int j = 1; j < j_min; j++)
-        {
-         tiles[i][j]->drawLowRes();
-        }
-}
-for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++)
-{
-        for(int j = j_max; j < (heightMap->w -tileSize)/tileSize; j++ )
-        {
-        tiles[i][j]->drawLowRes();
-        }
+	for(int j = 1; j < j_min; j++)
+	{
+	 tiles[i][j]->drawLowRes();
+	}
+}
+for(int i = 1; i < (heightMap->h -tileSize)/tileSize; i++) 
+{
+	for(int j = j_max; j < (heightMap->w -tileSize)/tileSize; j++ )
+	{
+	tiles[i][j]->drawLowRes();
+	}
 }
 
@@ -484,25 +503,25 @@
 
 if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
-        {
-        SDL_LockSurface(heightMap);
-        for(int i = 0 ; i < heightMap->h - 1  ; i ++)
-        {
-            for(int j = 0; j < heightMap->w  - 1  ;  j ++)
-            {
-
-
-                delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
-                Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
-
-                delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
-                Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
-
-
-                 normalVectorField[i][j] = b.cross(a);
-                 normalVectorField[i][j].normalize();
-
-             }
-        }
-        SDL_UnlockSurface(heightMap);
+	{
+	SDL_LockSurface(heightMap);
+	for(int i = 0 ; i < heightMap->h - 1  ; i ++)
+	{
+	    for(int j = 0; j < heightMap->w  - 1  ;  j ++)
+	    {
+
+
+		delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
+		Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
+
+		delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
+		Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
+
+
+		 normalVectorField[i][j] = b.cross(a);
+		 normalVectorField[i][j].normalize();
+		  
+	     }
+	}
+	SDL_UnlockSurface(heightMap);
 
 }
Index: branches/height_map_merge/src/lib/graphics/importer/height_map.h
===================================================================
--- branches/height_map_merge/src/lib/graphics/importer/height_map.h	(revision 6540)
+++ branches/height_map_merge/src/lib/graphics/importer/height_map.h	(revision 6579)
@@ -17,7 +17,7 @@
 
 
-#define texRate      4
+#define texRate      22
 #define texRatef     4.0f
-#define tileSize     64
+#define tileSize     32
 
 class SDL_Surface;
Index: branches/height_map_merge/src/world_entities/terrain.cc
===================================================================
--- branches/height_map_merge/src/world_entities/terrain.cc	(revision 6540)
+++ branches/height_map_merge/src/world_entities/terrain.cc	(revision 6579)
@@ -43,4 +43,23 @@
   this->loadParams(root);
 
+   this->heightMapMaterial = new Material(); 
+   heightMapMaterial->setTransparency(1.0);
+   heightMapMaterial->setIllum(0.2);
+
+   heightMapMaterial->setDiffuse(1.0,1.0,1.0);
+   heightMapMaterial->setAmbient(1.0,1.0,1.0 );
+   heightMapMaterial->setSpecular(1.0,1.0,1.0);
+   heightMapMaterial->setShininess(.5);
+   heightMapMaterial->setTransparency(1.0);
+
+   heightMapMaterial->diffuseTexture = NULL;
+   heightMapMaterial->ambientTexture = NULL;
+   heightMapMaterial->specularTexture = NULL;
+  
+   const  char* texture_name = "pictures/ground.tga";
+   heightMapMaterial->setDiffuseMap(texture_name);
+   heightMapMaterial->setAmbientMap(texture_name);
+   heightMapMaterial->setSpecularMap(texture_name); 	
+   
 //  if (this->model != NULL)
     //this->ssp = new SpatialSeparation((Model*)this->model, 10.0f);
@@ -135,4 +154,7 @@
 
   this->heightMap = new HeightMap(hmName, hmColorName);
+  heightMap->scale(Vector(23.0f,3.5f,23.0f));
+  heightMap->shift(Vector(-1000.0,-90.0,-4000.0));
+  heightMap->load();
   delete[] hmName;
   delete[] hmColorName;
@@ -187,6 +209,14 @@
     this->vegetation->draw();
 
-  if(this->heightMap != NULL)
-    this->heightMap->draw();
+  if(this->heightMap)
+	{
+	this->heightMapMaterial->select();
+    	
+   
+	// glEnable(GL_LIGHTING);
+ 	glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
+  	glEnable (GL_COLOR_MATERIAL) ;
+	this->heightMap->draw();
+	}
   glPopMatrix();
 
