Index: branches/water/src/story_entities/game_world.cc
===================================================================
--- branches/water/src/story_entities/game_world.cc	(revision 8241)
+++ branches/water/src/story_entities/game_world.cc	(revision 8249)
@@ -605,5 +605,4 @@
 void GameWorld::renderPassRefraction()
 {
-
     // clear buffer
   glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
Index: branches/water/src/world_entities/environments/mapped_water.cc
===================================================================
--- branches/water/src/world_entities/environments/mapped_water.cc	(revision 8241)
+++ branches/water/src/world_entities/environments/mapped_water.cc	(revision 8249)
@@ -81,20 +81,22 @@
   //mat.select();
   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
-  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-  
+  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureReflection);
+
+
   unsigned int* pTextureRefraction = new unsigned int [this->textureSize * this->textureSize * channels];
   memset(pTextureRefraction, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
-
-
-  // Set the texture quality
   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTextureRefraction);
+
+  // Set the texture quality
+
 
   // Since we stored the texture space with OpenGL, we can delete the image data
@@ -238,5 +240,5 @@
   // In order to line up the reflection nicely with the world we have to translate
   // the world to the position of our reflected surface, multiplied by two.
-  glEnable(GL_CLIP_PLANE0);
+  //glEnable(GL_CLIP_PLANE0);
   Vector pos = State::getCameraNode()->getAbsCoor();
   if(pos.y > waterHeight)
@@ -247,9 +249,9 @@
 
     // Since the world is updside down we need to change the culling to FRONT
-    glCullFace(GL_FRONT);
+    //glCullFace(GL_FRONT);
 
     // Set our plane equation and turn clipping on
     double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
-    glClipPlane(GL_CLIP_PLANE0, plane);
+    //glClipPlane(GL_CLIP_PLANE0, plane);
   }
   else
@@ -258,5 +260,5 @@
     // but just render it clipped so only the top is drawn.
     double plane[4] = {0.0, 1.0, 0.0, waterHeight};
-    glClipPlane(GL_CLIP_PLANE0, plane);
+    //glClipPlane(GL_CLIP_PLANE0, plane);
   }
 }
@@ -265,20 +267,18 @@
 void MappedWater::deactivateReflection()
 {
-  glDisable(GL_CLIP_PLANE0);
-  glCullFace(GL_BACK);
-
-  mat.select();
+  //glDisable(GL_CLIP_PLANE0);
+  //glCullFace(GL_BACK);
+
+  //mat.select();
   /////glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
   ///mat.renderToTexture(0, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
   ///
 
-  mat.select();
   glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
 
   // Create the texture and store it on the video card
   glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
-  
-  
-  ///
+
+
   glPopMatrix();
   glPopAttrib();
@@ -286,5 +286,39 @@
 
 void MappedWater::activateRefraction()
-{
+{ 
+  // save viewport matrix and change the viewport size
+  glPushAttrib(GL_VIEWPORT_BIT);
+  glViewport(0,0, textureSize, textureSize);
+
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+
+  // If our camera is above the water we will render the scene flipped upside down.
+  // In order to line up the reflection nicely with the world we have to translate
+  // the world to the position of our reflected surface, multiplied by two.
+  //glEnable(GL_CLIP_PLANE0);
+  Vector pos = State::getCameraNode()->getAbsCoor();
+  if(pos.y > waterHeight)
+  {
+    // Translate the world, then flip it upside down
+    glTranslatef(0.0f, waterHeight*2.0f, 0.0f);
+    glScalef(1.0, -1.0, 1.0);
+
+    // Since the world is updside down we need to change the culling to FRONT
+    //glCullFace(GL_FRONT);
+
+    // Set our plane equation and turn clipping on
+    double plane[4] = {0.0, 1.0, 0.0, -waterHeight};
+    //glClipPlane(GL_CLIP_PLANE0, plane);
+  }
+  else
+  {
+    // If the camera is below the water we don't want to flip the world,
+    // but just render it clipped so only the top is drawn.
+    double plane[4] = {0.0, 1.0, 0.0, waterHeight};
+    //glClipPlane(GL_CLIP_PLANE0, plane);
+  }
+
+/*
   // To create the refraction and depth textures we do the same thing
   // we did for the reflection texture, except we don't need to turn
@@ -305,5 +339,5 @@
 
   // If the camera is above water, render the data below the water
-  glEnable(GL_CLIP_PLANE0);
+  glEnable(GL_CLIP_PLANE1);
   Vector pos = State::getCameraNode()->getAbsCoor();
   if(pos.y > waterHeight)
@@ -311,4 +345,5 @@
     double plane[4] = {0.0, -1.0, 0.0, waterHeight}; 
     glClipPlane(GL_CLIP_PLANE0, plane);
+
   }
   // If the camera is below the water, only render the data above the water
@@ -319,15 +354,20 @@
     glClipPlane(GL_CLIP_PLANE0, plane);
   }
+  PRINTF(0)("test");*/
 }
 
 void MappedWater::deactivateRefraction()
 {
-  glDisable(GL_CLIP_PLANE0);
-  glCullFace(GL_BACK);
-
-  mat.select();
-  //mat.renderToTexture(1, GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
-  //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
-  //mat.renderToTexture(0, GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, textureSize, textureSize, 0);
+  //glDisable(GL_CLIP_PLANE0);
+  //glCullFace(GL_BACK);
+
+
+  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(1));
+
+  // Create the texture and store it on the video card
+  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
+
+  glPopMatrix();
+  glPopAttrib();
 
   // Bind the current scene to our refraction texture
@@ -339,5 +379,3 @@
 //  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, textureSize, textureSize, 0);
 
-  glPopMatrix();
-  glPopAttrib();
-}
+}
