Index: branches/terrain/src/lib/graphics/importer/terrain/frustum.h
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/frustum.h	(revision 8965)
+++ branches/terrain/src/lib/graphics/importer/terrain/frustum.h	(revision 9071)
@@ -20,6 +20,6 @@
 
 
-#define MAX_CLIP_DISTANCE 400.0f
-#define m( _row,_col )  _m[_col*4+_row-5]
+#define MAX_CLIP_DISTANCE 800.0f
+#define m( _col, _row )  _m[_row*4+_col]
 
 #define CHECK_GL_ERROR( _d ) do { \
@@ -93,39 +93,28 @@
 		inline void setFrustum( float *_m )
 		{
-			planes[NEAR].setCoefficients(
-							 m( 3, 1 ) + m( 4, 1 ),
-							 m( 3, 2 ) + m( 4, 2 ),
-							 m( 3, 3 ) + m( 4, 3 ),
-							 m( 3, 4 ) + m( 4, 4 ) );
-							
-			planes[FAR].setCoefficients( 
-							-m( 3, 1 ) + m( 4, 1 ),
-							-m( 3, 2 ) + m( 4, 2 ),
-							-m( 3, 3 ) + m( 4, 3 ),
-							-m( 3, 4 ) + m( 4, 4 ) );
-							
-			planes[BOTTOM].setCoefficients(
-							 m( 2, 1 ) + m( 4, 1 ),
-							 m( 2, 2 ) + m( 4, 2 ),
-							 m( 2, 3 ) + m( 4, 3 ),
-							 m( 2, 4 ) + m( 4, 4 ) );
-							
-			planes[TOP].setCoefficients(  
-							-m( 2, 1 ) + m( 4, 1 ),
-							-m( 2, 2 ) + m( 4, 2 ),
-							-m( 2, 3 ) + m( 4, 3 ),
-							-m( 2, 4 ) + m( 4, 4 ) );
-							
-			planes[LEFT].setCoefficients(  
-							 m( 1, 1 ) + m( 4, 1 ),
-							 m( 1, 2 ) + m( 4, 2 ),
-							 m( 1, 3 ) + m( 4, 3 ),
-							 m( 1, 4 ) + m( 4, 4 ) );
-							
-			planes[RIGHT].setCoefficients(
-							-m( 1, 1 ) + m( 4, 1 ),
-							-m( 1, 2 ) + m( 4, 2 ),
-							-m( 1, 3 ) + m( 4, 3 ),
-							-m( 1, 4 ) + m( 4, 4 ) );
+			planes[NEAR].setCoefficients( m(2,0) + m(3,0),
+									  	  m(2,1) + m(3,1),
+									  	  m(2,2) + m(3,2),
+									      m(2,3) + m(3,3));
+			planes[FAR].setCoefficients( -m(2,0) + m(3,0),
+									     -m(2,1) + m(3,1),
+									     -m(2,2) + m(3,2),
+									     -m(2,3) + m(3,3));
+			planes[BOTTOM].setCoefficients( m(1,0) + m(3,0),
+									   		m(1,1) + m(3,1),
+									   		m(1,2) + m(3,2),
+									   		m(1,3) + m(3,3));
+			planes[TOP].setCoefficients(  -m(1,0) + m(3,0),
+									  -m(1,1) + m(3,1),
+									  -m(1,2) + m(3,2),
+									  -m(1,3) + m(3,3));
+			planes[LEFT].setCoefficients(  m(0,0) + m(3,0),
+									   m(0,1) + m(3,1),
+									   m(0,2) + m(3,2),
+									   m(0,3) + m(3,3));
+			planes[RIGHT].setCoefficients(-m(0,0) + m(3,0),
+									  -m(0,1) + m(3,1),
+									  -m(0,2) + m(3,2),
+									  -m(0,3) + m(3,3));
 							
 			if ( planes[NEAR].d +planes[FAR].d  > MAX_CLIP_DISTANCE ) {
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 8965)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 9071)
@@ -28,13 +28,14 @@
 	SDL_Surface *tmpData = IMG_Load( full.c_str() );
  	if ( !tmpData ) {
-		PRINTF(0)( "I' sorry, I can't load %s\n", full.c_str() );
+		PRINT(0)( "I' sorry, I can't load %s\n", full.c_str() );
 		return;
 	}		
 	if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) {
-		PRINTF(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
+		PRINT(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
 		return;
 	}
 	if ( tmpData->format->BytesPerPixel != 1 ) {
-		PRINTF(0)( "The elevetation map must be an 8bit image!" );
+		PRINT(0)( "The elevetation map must be an 8bit image not %d", 
+			tmpData->format->BytesPerPixel*8 );
 		return;
 	}
@@ -148,5 +149,4 @@
 	switch( _node->cull() ) {
 		case Frustum::INTERSECT:
-			//printf( "partially inside frustum\n" );
 			if ( !_node->isChildless() ) {
 				pTerrainQuad *children = _node->getChildren();
@@ -160,5 +160,4 @@
 			break;
 		case Frustum::INSIDE:
-			//printf( "fully inside frustum\n" );			
 			showPages( _node->getXOffset(), 
 					   _node->getZOffset(), 
@@ -167,5 +166,4 @@
 			break;
 		case Frustum::OUTSIDE:
-			cullCount+= (_node->getWidth()-1)*(_node->getHeight()-1);
 			break;
 	}
@@ -249,7 +247,7 @@
 	//Due to some reason, the OpenGL implementors chose the plane equation
 	//to an array of doubles. So we will make them happy.
-	double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };
-	glEnable( GL_CLIP_PLANE0 );
-	glClipPlane( GL_CLIP_PLANE0, farPlane );
+	//double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };
+	//glEnable( GL_CLIP_PLANE0 );
+	//glClipPlane( GL_CLIP_PLANE0, farPlane );
 	glPushAttrib( GL_ALL_ATTRIB_BITS );
 	glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
@@ -273,64 +271,4 @@
 	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
 	cullCount = 0;
-	
-	/*// Lets see which pages are visible.
-	determineVisiblePages( root );
-	int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD;
-	pTerrainPage neighbor = NULL;
-	page = activePages;
-	bool dirty;
-	current = 0;
-	BufferInfo bi;
-	broker->acquire( bi.vbIdentifier, bi.ibIdentifier );
-	buffers.push_back( bi );
-	int dirtyRounds = 0;
-	do {
-		dirtyRounds++;
-		dirty = false;
-		page = activePages;
-		while ( page ) {
-			if ( !page->isActive() ) {
-				pTerrainPage tmp = page;
-				page = tmp->getNext();
-				tmp->setVisibility( false );
-				continue;
-			}
-			wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD();
-			if ( ( neighbor = page->getLeft() ) && ( neighbor->isActive() ) ) 
-				wantedLeft = neighbor->getWantedLOD();
-			if ( ( neighbor = page->getRight() ) && ( neighbor->isActive() ) ) 
-				wantedRight = neighbor->getWantedLOD();
-			if ( ( neighbor = page->getTop() ) && ( neighbor->isActive() ) ) 
-				wantedTop = neighbor->getWantedLOD();
-			if ( ( neighbor = page->getBottom() ) && ( neighbor->isActive() ) ) 
-				wantedBottom = neighbor->getWantedLOD();			
-		
-			minLOD = std::min( std::min( wantedBottom, wantedTop ), 
-				std::min( wantedLeft, wantedRight ) );	
-			if ( minLOD < page->getWantedLOD()-1 ) {
-				page->setWantedLOD( minLOD+1 );
-				dirty = true;
-			}	
-			page = page->getNext();
-		}
-	} while ( dirty );
-	
-	page = activePages;
-	while ( page ) {
-		assert( page->isActive() );
-		page->updateTesselation();
-		page = page->getNext();
-	}
-	//If there is some data in the buffer, we need to upload the data
-	//into the vram...
-	if ( buffers[current].numIndices != 0 ) {
-		BufferInfo bi = buffers[current];	
-		glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier );
-		glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ), 
-			vertices, GL_DYNAMIC_DRAW_ARB );
-		glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier );
-		glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 
-			indices, GL_DYNAMIC_DRAW_ARB );
-	}*/
 	glEnable( GL_BLEND );
 	glDepthFunc( GL_LEQUAL );
@@ -389,5 +327,4 @@
 		}
 	}
-			
 	glClientActiveTextureARB( GL_TEXTURE1_ARB );	
 	glActiveTextureARB( GL_TEXTURE1_ARB );
@@ -412,5 +349,8 @@
 		break;
     case 2:
-        pixel = *(Uint16 *)p;
+		if ( SDL_BYTEORDER == SDL_BIG_ENDIAN )
+			pixel = p[0] << 8 | p[1]; 
+		else
+        	pixel = *(Uint16 *)p;
 		break;
     case 3:
@@ -424,5 +364,5 @@
 		break;
     default:
-        return 255;       /* shouldn't happen, but avoids warnings */
+        return 255; /* shouldn't happen, but avoids warnings */
     }
 	Uint8 r,g,b,a;
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain.h
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 8965)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 9071)
@@ -92,5 +92,5 @@
 			indices = new unsigned short[MAX_INDICES];
 #ifdef USE_VBO
-			broker = new BufferBroker( 200, MAX_VERTICES*sizeof( Vertex ), 
+			broker = new BufferBroker( 300, MAX_VERTICES*sizeof( Vertex ), 
 				MAX_INDICES*sizeof( short ) );
 #endif			
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 8965)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 9071)
@@ -237,6 +237,6 @@
 		for ( int z = 0; z < size; ++z ) {
 			alt = getAltitude( x, z );
-			min.y = fmin( min.y, alt );
-			max.y = fmax( max.y, alt );
+			min.y = fmin( min.y, alt-1.0f );
+			max.y = fmax( max.y, alt+1.0f );
 		}
 	}
@@ -272,5 +272,5 @@
 void TerrainPage::updateTesselation( )
 {
-
+	assert( wantedLOD < 5 && wantedLOD >= 0 );
 	if ( needsRetesselation() ) {
 		tesselate( wantedLOD );
Index: branches/terrain/src/world_entities/camera.cc
===================================================================
--- branches/terrain/src/world_entities/camera.cc	(revision 8965)
+++ branches/terrain/src/world_entities/camera.cc	(revision 9071)
@@ -34,5 +34,5 @@
   this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW5);
 
-  this->setFovy(60.0);
+  this->setFovy(90.0);
   this->setAspectRatio(1.2f);
   this->setClipRegion( .1, 40.0f );
