Index: trunk/src/lib/event/event_handler.cc
===================================================================
--- trunk/src/lib/event/event_handler.cc	(revision 6680)
+++ trunk/src/lib/event/event_handler.cc	(revision 6684)
@@ -262,5 +262,5 @@
     SDL_WM_GrabInput(SDL_GRAB_OFF);
   else
-    ;// SDL_WM_GrabInput(SDL_GRAB_ON);
+    SDL_WM_GrabInput(SDL_GRAB_ON);
 }
 
Index: trunk/src/world_entities/environments/water.cc
===================================================================
--- trunk/src/world_entities/environments/water.cc	(revision 6680)
+++ trunk/src/world_entities/environments/water.cc	(revision 6684)
@@ -69,14 +69,14 @@
 
   LoadParam(root, "size", this, Water, setSize)
-      .describe("the size of the WaterSurface")
-      .defaultValues(2, 1.0f, 1.0f);
+  .describe("the size of the WaterSurface")
+  .defaultValues(2, 1.0f, 1.0f);
 
   LoadParam(root, "resolution", this, Water, setResolution)
-      .describe("sets the resolution of the water surface")
-      .defaultValues(2, 10, 10);
+  .describe("sets the resolution of the water surface")
+  .defaultValues(2, 10, 10);
 
   LoadParam(root, "height", this, Water, setHeight)
-      .describe("the height of the Waves")
-      .defaultValues(1, 0.5f);
+  .describe("the height of the Waves")
+  .defaultValues(1, 0.5f);
 }
 
@@ -91,7 +91,7 @@
   }
 
-//   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
-//   if (this->grid != NULL)
-//     this->grid = NULL;
+  //   WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();
+  //   if (this->grid != NULL)
+  //     this->grid = NULL;
 
   this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY);
@@ -126,22 +126,24 @@
 void Water::draw() const
 {
-  //SkyBox::enableCubeMap();
-
-  glBindTexture(GL_TEXTURE_2D, 15);
-  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
-  glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
-  glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
-  glEnable(GL_TEXTURE_GEN_S);
-  glEnable(GL_TEXTURE_GEN_T);
-
-  glEnable(GL_BLEND);
-  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  // this->waterShader->activateShader();
-//  this->waterMaterial->select();
-  WorldEntity::draw();
-  //Shader::deactivateShader();
-
-  SkyBox::disableCubeMap();
+  if (this->grid != NULL)
+  {
+    //SkyBox::enableCubeMap();
+    WorldEntity::draw();
+    glBindTexture(GL_TEXTURE_2D, 15);
+    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+
+    glEnable(GL_BLEND);
+    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    // this->waterShader->activateShader();
+    //  this->waterMaterial->select();
+    //Shader::deactivateShader();
+
+    SkyBox::disableCubeMap();
+  }
 }
 
@@ -150,16 +152,16 @@
   if (unlikely(this->velocities == NULL))
     return;
-/*
-    THE OLD USELESS ALGORITHM
-  phase += dt *.1;
-  for (unsigned int i = 0; i < this->grid->rows(); i++)
-  {
-    for (unsigned int j = 0; j < this->grid->columns(); j++)
+  /*
+      THE OLD USELESS ALGORITHM
+    phase += dt *.1;
+    for (unsigned int i = 0; i < this->grid->rows(); i++)
     {
-      this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
-          this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
+      for (unsigned int j = 0; j < this->grid->columns(); j++)
+      {
+        this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+
+            this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0);
+      }
     }
-  }
-  this->grid->rebuildNormals(this->height);*/
+    this->grid->rebuildNormals(this->height);*/
 
 
@@ -169,31 +171,46 @@
   // wave/advection
   // calc movement
-  for(j = 1; j < this->grid->rows() - 1; j++) {
-    for(i = 1; i < this->grid->columns() - 1; i++) {
+  for(j = 1; j < this->grid->rows() - 1; j++)
+  {
+    for(i = 1; i < this->grid->columns() - 1; i++)
+    {
       u =  this->grid->height(i+1,j)+ this->grid->height(i-1, j) +
-          this->grid->height(i, j+1) + this->grid->height(i, j-1) -
-          4 * this->grid->height(i, j);
+           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
+           4 * this->grid->height(i, j);
       this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height;
       this->grid->height(i, j) += dt * this->velocities[i][j];
     }
   }
-/*  // advect
-  for(j = 1; j < this->grid->rows() - 1; j++) {
-    for(i = 1; i < this->grid->columns() - 1; i++) {
-      this->grid->height(i, j) += dt * this->velocities[i][j];
-    }
-  }*/
+  // boundraries
+  for (j = 0; j < this->grid->rows(); j++)
+  {
+    this->grid->height(0,j) = this->grid->height(1,j);
+    this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j);
+  }
+  for (i = 0; i < this->grid->rows(); i++)
+  {
+    this->grid->height(i,0) = this->grid->height(i,1);
+    this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2);
+  }
+  /*  // advect
+    for(j = 1; j < this->grid->rows() - 1; j++) {
+      for(i = 1; i < this->grid->columns() - 1; i++) {
+        this->grid->height(i, j) += dt * this->velocities[i][j];
+      }
+    }*/
   // bound
-//   unsigned int w = this->grid->columns - 1;
-//   for(i = 0; i < this->grid->columns; i++) {
-//     _map[i][0].u[1] = _map[i][1  ].u[1];
-//     _map[i][w].u[1] = _map[i][w-1].u[1];
-//     _map[0][i].u[1] = _map[1  ][i].u[1];
-//     _map[w][i].u[1] = _map[w-1][i].u[1];
-//   }
+  //   unsigned int w = this->grid->columns - 1;
+  //   for(i = 0; i < this->grid->columns; i++) {
+  //     _map[i][0].u[1] = _map[i][1  ].u[1];
+  //     _map[i][w].u[1] = _map[i][w-1].u[1];
+  //     _map[0][i].u[1] = _map[1  ][i].u[1];
+  //     _map[w][i].u[1] = _map[w-1][i].u[1];
+  //   }
 
   // diffusion
-  for(j = 1; j < this->grid->rows() - 1; j++) {
-    for(i = 1; i < this->grid->columns() - 1 ; i++) {
+  for(j = 1; j < this->grid->rows() - 1; j++)
+  {
+    for(i = 1; i < this->grid->columns() - 1 ; i++)
+    {
       u = this->grid->height(i+1, j) + this->grid->height(i-1, j) +
           this->grid->height(i, j+1) + this->grid->height(i, j-1) -
@@ -204,19 +221,19 @@
 
   // calc normals
-//   float l[3];
-//   float m[3];
-//   for(j = 1; j < this->grid->rows() -1; j++) {
-//     for(i = 1; i < this->grid->columns() - 1; i++) {
-//       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
-//       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
-//       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
-//       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
-//       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
-//       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
-//       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
-//       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
-//       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
-//     }
-//   }
+  //   float l[3];
+  //   float m[3];
+  //   for(j = 1; j < this->grid->rows() -1; j++) {
+  //     for(i = 1; i < this->grid->columns() - 1; i++) {
+  //       l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;
+  //       l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;
+  //       l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;
+  //       m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;
+  //       m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;
+  //       m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;
+  //       this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];
+  //       this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];
+  //       this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];
+  //     }
+  //   }
   this->grid->rebuildNormals(this->height);
 }
