Index: /trunk/src/defs/class_id.h
===================================================================
--- /trunk/src/defs/class_id.h	(revision 7784)
+++ /trunk/src/defs/class_id.h	(revision 7785)
@@ -179,4 +179,5 @@
   CL_PLANET                     =    0x00000309,
   CL_BUILDING                   =    0x00000310,
+  CL_MAPPED_WATER               =    0x00000311,
 
   // Playables
Index: /trunk/src/lib/graphics/importer/material.cc
===================================================================
--- /trunk/src/lib/graphics/importer/material.cc	(revision 7784)
+++ /trunk/src/lib/graphics/importer/material.cc	(revision 7785)
@@ -45,5 +45,4 @@
   this->setTransparency(1.0);
 
-  this->diffuseTexture = NULL;
   this->ambientTexture = NULL;
   this->specularTexture = NULL;
@@ -61,32 +60,56 @@
   PRINTF(5)("delete Material %s.\n", this->getName());
 
-  if (this->diffuseTexture != NULL)
-  {
-    ResourceManager::getInstance()->unload(this->diffuseTexture);
-  }
+  while(!this->textures.empty())
+  {
+    if (this->textures.back() != NULL)
+      ResourceManager::getInstance()->unload(this->textures.back());
+    this->textures.pop_back();
+  }
+
   if (this->ambientTexture != NULL)
     ResourceManager::getInstance()->unload(this->ambientTexture);
   if (this->specularTexture != NULL)
     ResourceManager::getInstance()->unload(this->specularTexture);
-}
-
-Material& Material::operator=(const Material& m)
-{
-  this->setIllum(m.illumModel);
-  this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);
-  this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);
-  this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);
-  this->setShininess(m.shininess);
-  this->setTransparency(m.transparency);
-
-  if (this->diffuseTexture != NULL)
-    ResourceManager::getInstance()->unload(this->diffuseTexture);
-  if (m.diffuseTexture != NULL)
-    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
-  this->ambientTexture = NULL; /// FIXME
-  this->specularTexture = NULL; /// FIXME
-
-  this->setName(m.getName());
-}
+
+  if (this == Material::selectedMaterial)
+    Material::selectedMaterial = NULL;
+}
+
+
+const Material* Material::selectedMaterial = NULL;
+
+const GLenum Material::glTextureArbs[] =
+{
+  GL_TEXTURE0,
+  GL_TEXTURE1,
+  GL_TEXTURE2,
+  GL_TEXTURE3,
+  GL_TEXTURE4,
+  GL_TEXTURE5,
+  GL_TEXTURE6,
+  GL_TEXTURE7
+};
+
+
+/// TODO FIX THIS
+// Material& Material::operator=(const Material& m)
+// {
+//   this->setIllum(m.illumModel);
+//   this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);
+//   this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);
+//   this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);
+//   this->setShininess(m.shininess);
+//   this->setTransparency(m.transparency);
+//
+//   if (this->diffuseTexture != NULL)
+//     ResourceManager::getInstance()->unload(this->diffuseTexture);
+//   if (m.diffuseTexture != NULL)
+//     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
+//   this->ambientTexture = NULL; /// FIXME
+//   this->specularTexture = NULL; /// FIXME
+//
+//   this->setName(m.getName());
+// }
+
 
 
@@ -94,22 +117,23 @@
  *  sets the material with which the following Faces will be painted
  */
-bool Material::select () const
-{
+bool Material::select() const
+{
+  if (unlikely(this == Material::selectedMaterial))
+      return true;
+
+
   // setting diffuse color
   glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency);
-//  glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
-
   // setting ambient color
   glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
-
   // setting up Sprecular
   glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
-
   // setting up Shininess
   glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
 
+
   // setting the transparency
   if (this->transparency < 1.0 ||       /* This allows alpha blending of 2D textures with the scene */
-      (this->diffuseTexture && this->diffuseTexture->hasAlpha()))
+      (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha()))
   {
     glEnable(GL_BLEND);
@@ -117,8 +141,7 @@
   }
   else
-    {
-      glDisable(GL_BLEND);
-      //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1);
-    }
+  {
+    glDisable(GL_BLEND);
+  }
 
 
@@ -129,14 +152,39 @@
     glShadeModel(GL_SMOOTH);
 
-  if (this->diffuseTexture != NULL)
+  if (likely(Material::selectedMaterial != NULL))
+  {
+    for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
     {
+        glActiveTexture(Material::glTextureArbs[i]);
+        glBindTexture(GL_TEXTURE_2D, 0);
+        glDisable(GL_TEXTURE_2D);
+    }
+  }
+
+  for(unsigned int i = 0; i < this->textures.size(); ++i)
+  {
+    if (likely(this->textures[i] != NULL))
+    {
+      glActiveTexture(Material::glTextureArbs[i]);
       glEnable(GL_TEXTURE_2D);
-      glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
+      if(this->textures[i]->hasAlpha())
+      {
+        glEnable(GL_BLEND);
+      }
+      glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture());
     }
-  else
-    {
-      glDisable(GL_TEXTURE_2D);
-      glBindTexture(GL_TEXTURE_2D, 0);
-    }
+  }
+  Material::selectedMaterial = this;
+
+  /*  if (this->diffuseTexture != NULL)
+      {
+        glEnable(GL_TEXTURE_2D);
+        glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
+      }
+    else
+      {
+        glDisable(GL_TEXTURE_2D);
+        glBindTexture(GL_TEXTURE_2D, 0);
+      }*/
 }
 
@@ -162,5 +210,5 @@
 /**
  *  Sets the Material Diffuse Color.
- * @param r Red Color Channel.
+ * @param r Red Color Channel.a
  * @param g Green Color Channel.
  * @param b Blue Color Channel.
@@ -226,5 +274,5 @@
   this->specular[2] = b;
   this->specular[3] = 1.0;
- }
+}
 
 /**
@@ -285,21 +333,72 @@
 // MAPPING //
 
+void Material::setDiffuseMap(Texture* texture, unsigned int textureNumber)
+{
+  assert(textureNumber < Material::getMaxTextureUnits());
+
+  if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
+    ResourceManager::getInstance()->unload(this->textures[textureNumber]);
+
+  if (this->textures.size() <= textureNumber)
+    this->textures.resize(textureNumber+1, NULL);
+
+  //! @todo check if RESOURCE MANAGER is availiable
+  this->textures[textureNumber] = texture;
+}
+
+
+/**
+ * @brief Sets the Materials Diffuse Map
+ * @param dMap the Name of the Image to Use
+*/
+void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber)
+{
+  assert(textureNumber < Material::getMaxTextureUnits());
+
+  PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str());
+  if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
+    ResourceManager::getInstance()->unload(this->textures[textureNumber]);
+
+  if (this->textures.size() <= textureNumber)
+    this->textures.resize(textureNumber+1, NULL);
+
+  //! @todo check if RESOURCE MANAGER is availiable
+  if (!dMap.empty())
+  {
+
+    this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
+  }
+  else
+  {
+    this->textures[textureNumber] = NULL;
+  }
+}
+
 /**
  *  Sets the Materials Diffuse Map
- * @param dMap the Name of the Image to Use
-*/
-void Material::setDiffuseMap(const std::string& dMap, GLenum target)
-{
-  PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str());
-  if (this->diffuseTexture != NULL)
-    ResourceManager::getInstance()->unload(this->diffuseTexture);
-
-  //! @todo check if RESOURCE MANAGER is availiable
-  //! @todo Textures from .mtl-file need special care.
-  if (!dMap.empty())
-    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
+ * @param surface pointer to SDL_Surface which shall be used as texture
+*/
+void Material::setSDLDiffuseMap(SDL_Surface *surface, GLenum target, unsigned int textureNumber)
+{
+  assert(textureNumber < Material::getMaxTextureUnits());
+
+
+  if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
+    ResourceManager::getInstance()->unload(this->textures[textureNumber]);
+
+  if (this->textures.size() <= textureNumber)
+    this->textures.resize(textureNumber+1, NULL);
+
+  if(surface != NULL)
+  {
+    this->textures[textureNumber] = new Texture(surface, GL_TEXTURE_2D);
+  }
   else
-    this->diffuseTexture = NULL;
-}
+  {
+    this->textures[textureNumber] = NULL;
+  }
+
+}
+
 
 /**
@@ -332,4 +431,12 @@
 void Material::setBump(const std::string& bump)
 {
-
-}
+}
+
+
+
+int Material::getMaxTextureUnits()
+{
+  int maxTexUnits = 0;
+  glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits);
+  return maxTexUnits;
+}
Index: /trunk/src/lib/graphics/importer/material.h
===================================================================
--- /trunk/src/lib/graphics/importer/material.h	(revision 7784)
+++ /trunk/src/lib/graphics/importer/material.h	(revision 7785)
@@ -1,8 +1,8 @@
 /*!
-  \file material.h
-  \brief Contains the Material Class that handles Material for 3D-Objects.
-  @todo free SDL-surface when deleting Material.
-  @todo delete imgNameWithPath after use creation.
-*/
+ * @file material.h
+ * @brief Contains the Material Class that handles Material for 3D-Objects.
+ * @todo free SDL-surface when deleting Material.
+ * @todo delete imgNameWithPath after use creation.
+ */
 
 #ifndef _MATERIAL_H
@@ -10,11 +10,11 @@
 #include "base_object.h"
 
+
 #if HAVE_CONFIG_H
 #include <config.h>
 #endif /* HAVE_CONFIG_H */
 
-#ifndef NULL
-#define NULL 0            //!< a pointer to NULL
-#endif
+#include <vector>
+#include "SDL_image.h"
 
 #include "texture.h"
@@ -25,49 +25,66 @@
 class Material : public BaseObject
 {
- public:
-  Material (const std::string& mtlName = "");
-  virtual ~Material ();
+  public:
+    Material (const std::string& mtlName = "");
+    virtual ~Material ();
 
-  Material& operator=(const Material& material);
+    Material& operator=(const Material& material);
 
-  bool select () const;
+    bool select () const;
 
-  void setIllum (int illum);
-  void setIllum (char* illum);
-  int getIllumModel() const { return this->illumModel; };
-  void setDiffuse (float r, float g, float b);
-  void setDiffuse (char* rgb);
-  void setAmbient (float r, float g, float b);
-  void setAmbient (char* rgb);
-  void setSpecular (float r, float g, float b);
-  void setSpecular (char* rgb);
-  void setShininess (float shini);
-  void setShininess (char* shini);
-  void setTransparency (float trans);
-  void setTransparency (char* trans);
-  void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; };
+    void setIllum (int illum);
+    int getIllumModel() const { return this->illumModel; };
+    void setDiffuse (float r, float g, float b);
+    void setAmbient (float r, float g, float b);
+    void setSpecular (float r, float g, float b);
+    void setShininess (float shini);
+    void setTransparency (float trans);
+    void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; };
 
- // MAPPING //
-  void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D);
-  void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
-  void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
-  void setBump(const std::string& bump);
-  GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; };
 
-  static void addTexturePath(const std::string& pathName);
+    // TODO Move them out of here
+    void setIllum (char* illum);
+    void setDiffuse (char* rgb);
+    void setAmbient (char* rgb);
+    void setSpecular (char* rgb);
+    void setShininess (char* shini);
+    void setTransparency (char* trans);
+
+
+    // MAPPING //
+    void setDiffuseMap(Texture* texture, unsigned int textureNumber = 0);
+    void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
+    void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
+
+    void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
+    void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
+    void setBump(const std::string& bump);
+    GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i]->getTexture() : 0; };
+
+    static void addTexturePath(const std::string& pathName);
+
+  public:
+    static const GLenum glTextureArbs[];  //!< The Texture ARB's
+
+    static int getMaxTextureUnits();
 
   private:
-    int         illumModel;       //!< The IlluminationModel is either flat or smooth.
-    float       diffuse [4];      //!< The diffuse color of the Material.
-    float       ambient [4];      //!< The ambient color of the Material.
-    float       specular [4];     //!< The specular color of the Material.
-    float       shininess;        //!< The shininess of the Material.
-    float       transparency;     //!< The transperency of the Material.
-    GLenum      sFactor;
-    GLenum      tFactor;
+    static const Material* selectedMaterial; //!< The currently selected material.
 
-    Texture*    diffuseTexture;   //!< The diffuse texture of the Material.
-    Texture*    ambientTexture;   //!< The ambient texture of the Material.
-    Texture*    specularTexture;  //!< The specular texture of the Material.
+    int              illumModel;       //!< The IlluminationModel is either flat or smooth.
+    float            diffuse [4];      //!< The diffuse color of the Material.
+    float            ambient [4];      //!< The ambient color of the Material.
+    float            specular [4];     //!< The specular color of the Material.
+    float            shininess;        //!< The shininess of the Material.
+    float            transparency;     //!< The transperency of the Material.
+    GLenum           sFactor;
+    GLenum           tFactor;
+
+    std::vector<Texture*> textures;    //!< An Array of Textures.
+
+    Texture*         ambientTexture;   //!< The ambient texture of the Material.
+    Texture*         specularTexture;  //!< The specular texture of the Material.
+
+
 };
 #endif
Index: /trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- /trunk/src/lib/graphics/importer/texture.cc	(revision 7784)
+++ /trunk/src/lib/graphics/importer/texture.cc	(revision 7785)
@@ -20,5 +20,4 @@
 #include "debug.h"
 #include "compiler.h"
-#include <math.h>
 
 // INCLUDING SDL_Image
@@ -29,21 +28,10 @@
 #endif
 
-/**
- * @brief Constructor for a Texture
-*/
-Texture::Texture(const std::string& imageName, GLenum target)
-{
-  this->setClassID(CL_TEXTURE, "Texture");
-
+
+TextureData::TextureData()
+{
   this->bAlpha = false;
   this->texture = 0;
   this->image = NULL;
-  this->priority = 0.5;
-
-  if (!imageName.empty())
-  {
-    this->setName(imageName);
-    this->loadImage(imageName, target);
-  }
 }
 
@@ -52,7 +40,7 @@
  * @brief Destructor of a Texture
  *
- * Frees Data, and deletes the textures from GL
- */
-Texture::~Texture()
+ *  Frees Data, and deletes the textures from GL
+ */
+TextureData::~TextureData()
 {
   if (this->texture != 0)
@@ -64,4 +52,111 @@
 
 /**
+ * @brief Loads an SDL_Surface.
+ */
+bool TextureData::loadSurface(SDL_Surface* surface, GLenum target)
+{
+  if (Texture::getTextureEnableState())
+  {
+    SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha);
+    if (newSurf != NULL)
+    {
+      this->setSurface(newSurf);
+      this->setTexture(Texture::loadTexToGL(newSurf, target));
+      return true;
+    }
+  }
+  return false;
+}
+
+
+
+/**
+ * @brief set the surface this Texture handles
+ * @param newSurface the new Surface to set as the image for this Texture.
+ *
+ * This deletes the old version of the stored Texture,
+ * and sets the newly given Surface as current.
+ */
+bool TextureData::setSurface(SDL_Surface* newSurface)
+{
+  if (this->image != NULL)
+    SDL_FreeSurface(this->image);
+
+  this->image = newSurface;
+
+  return (this->image != NULL);
+}
+
+
+
+bool TextureData::setTexture(GLuint texture)
+{
+     // unload the old Texture.
+  if (this->texture != 0 && glIsTexture(this->getTexture()))
+  {
+    glDeleteTextures(1, &this->texture);
+  }
+  this->texture = texture;
+  return (texture != 0);
+}
+
+
+
+
+
+Texture::Texture(GLenum target)
+{
+  this->init();
+  GLuint texture;
+  this->generateTexture(texture, target);
+  this->data->setTexture(texture);
+}
+
+/**
+ *  Constructor for a Texture
+ */
+Texture::Texture(const std::string& imageName, GLenum target)
+{
+  this->init();
+
+  if (!imageName.empty())
+  {
+    this->setName(imageName);
+    this->loadImage(imageName, target);
+  }
+}
+
+
+
+Texture::Texture(SDL_Surface* surface, GLenum target)
+{
+  this->init();
+
+  if(surface != NULL)
+  {
+    this->data->loadSurface(surface, target);
+  }
+}
+
+void Texture::init()
+{
+  this->setClassID(CL_TEXTURE, "Texture");
+
+  this->data = CountPointer<TextureData>(new TextureData());
+
+  this->priority = 0.5;
+}
+
+/**
+ * @brief Destructor of a Texture
+ *
+ * Frees Data, and deletes the textures from GL
+ */
+Texture::~Texture()
+{
+}
+
+
+/**
  * @brief loads an Image from a file to a Texture
  * @param imageName The image to load
@@ -71,33 +166,13 @@
   if (Texture::texturesEnabled)
   {
-    if (this->image != NULL)
-    {
-      SDL_FreeSurface(this->image);
-      this->image = NULL;
-    }
-    if (this->texture != 0)
-    {
-      glDeleteTextures(1, &this->texture);
-      this->texture = 0;
-    }
     if (!imageName.empty())
     {
       SDL_Surface* tmpSurf;
-      if (this->texture != 0 && glIsTexture(this->texture))
-        glDeleteTextures(1, &this->texture);
+
       // load the new Image to memory
       tmpSurf = IMG_Load(imageName.c_str());
       if(tmpSurf != NULL)
       {
-        PRINTF(4)("loading Image %s\n", imageName.c_str());
-        bool hasAlpha;
-        SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha);
-        if (newSurf != NULL)
-        {
-          this->setSurface(newSurf);
-          this->setAlpha(hasAlpha);
-          this->setTexture(Texture::loadTexToGL(newSurf, target));
-        }
-
+        this->data->loadSurface(tmpSurf, target);
         SDL_FreeSurface(tmpSurf);
         return true;
@@ -106,5 +181,5 @@
       {
         PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
-        this->texture = 0;
+        this->setTexture(0);
         return false;
       }
@@ -119,5 +194,4 @@
 }
 
-
 /**
  * @brief rebuilds the texture.
@@ -127,36 +201,12 @@
 bool Texture::rebuild()
 {
-  if (this->texture != 0)
-  {
-    if (glIsTexture(this->texture))
-      glDeleteTextures(1,&this->texture);
-    this->setTexture(0);
-  }
-
-  if (this->image != NULL)
+  this->data->setTexture(0);
+
+  if (this->data->getStoredImage() != NULL)
   {
     PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
-    this->setTexture(loadTexToGL(this->image));
-  }
-}
-
-
-/**
- * @brief set the surface this Texture handles
- * @param newSurface the new Surface to set as the image for this Texture.
- *
- * This deletes the old version of the stored Texture,
- * and sets the newly given Surface as current.
- */
-bool Texture::setSurface(SDL_Surface* newSurface)
-{
-  if (this->image != NULL)
-    SDL_FreeSurface(this->image);
-
-  this->image = newSurface;
-
-  return (this->image != NULL);
-}
-
+    this->setTexture(Texture::loadTexToGL(this->data->getStoredImage()));
+  }
+}
 
 bool Texture::texturesEnabled = true;
@@ -181,5 +231,5 @@
  * @returns a !!new!! Surface, that is loadable by openGL.
  */
-SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
+SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
 {
   assert(surface != NULL);
@@ -222,5 +272,5 @@
     return NULL;
 
-  /* Copy the surface into the GL texture image */
+  /* Copy the surface into the GL texture this->data->getStoredImage() */
   area.x = 0;
   area.y = 0;
@@ -245,18 +295,18 @@
  * @returns The ID of the texture.
  */
-GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) const
-{
-  //   if (this->texture != 0 && glIsTexture(this->texture))
-  //     glDeleteTextures(1, &this->texture);
-  //   this->texture = 0;
+GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target)
+{
+  //   if (this->data->getTexture() != 0 && glIsTexture(this->data->getTexture()))
+  //     glDeleteTextures(1, &this->data->getTexture());
+  //   this->data->getTexture() = 0;
   assert(surface != NULL);
 
   int      errorCode = 0;           //!< the error code for the texture loading functions
-  GLuint   texture;                 //!< the OpenGL texture handle
+  GLuint   texture = 0;             //!< the OpenGL texture handle
   int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
   int      mipmapWidth = 0;         //!< the width of the mipmap
   int      mipmapHight = 0;         //!< the height of the mipmap
   GLenum   format = GL_RGB;
-  if (this->bAlpha)
+  if (surface->format->BitsPerPixel == 32)
   {
     format = GL_RGBA;
@@ -268,7 +318,6 @@
   }
 
-  /* Create an OpenGL texture for the image */
-  glGenTextures(1, &texture);
-  glBindTexture(target, texture);
+  /* Create an OpenGL texture for the this->data->getStoredImage() */
+  Texture::generateTexture(texture, target);
 
 //   glTexImage2D(target,  0,  format,
@@ -277,16 +326,9 @@
 //                surface->pixels);
 
-  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
-  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
-
-  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/);
-  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
-
-
-  /* control the mipmap levels */
-  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
-  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+///  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
+///  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
+
+  /// TODO CHECK THIS BACK in
+  //glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
 
   /* build the Texture  OpenGL V >= 1.1 */
@@ -306,2 +348,20 @@
 }
 
+void Texture::generateTexture(GLuint& texture, GLenum target)
+{
+  if (texture == 0 && !glIsTexture(texture))
+  {
+    glGenTextures(1, &texture);
+  }
+  glBindTexture(target, texture);
+
+  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
+  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
+
+  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+  /* control the mipmap levels */
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+}
Index: /trunk/src/lib/graphics/importer/texture.h
===================================================================
--- /trunk/src/lib/graphics/importer/texture.h	(revision 7784)
+++ /trunk/src/lib/graphics/importer/texture.h	(revision 7785)
@@ -10,49 +10,86 @@
 
 #include "glincl.h"
+#include "count_pointer.h"
 
 /* Forward Declaration */
 struct SDL_Surface;
 
-//! A Class, that reads in Textures from different fileformats.
-  class Texture : public BaseObject
-  {
-    public:
-      Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);
-  //  Texture(TEXTURE_TYPE type, int resolution);
-      virtual ~Texture();
 
-      bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
-      virtual bool rebuild();
+class TextureData
+{
+  public:
+    TextureData();
+    ~TextureData();
 
-      /** @returns The textureID of this texture.  */
-      inline GLuint getTexture() const { return this->texture; };
-      /** @returns true if texture has alpha, false otherwise */
-      inline bool hasAlpha() const {return bAlpha;}
-      /** @returns the stored image of this Texture */
-      const SDL_Surface* const getStoredImage() const { return this->image; };
+    inline GLuint getTexture() const { return this->texture; };
+    /** @returns true if texture has alpha, false otherwise */
+    inline bool hasAlpha() const  {return this->bAlpha; }
+    /** @returns the stored image of this Texture */
+    const SDL_Surface* const getStoredImage() const { return this->image; };
+
+    bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
 
 
 
-      static void setTextureEnableState(bool texturesEnabled);
-      /** @returns true if Textures are enabled */
-      inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
+    bool rebuild();
 
-      // Utility functionality:
-      SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const;
-      GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D) const;
+    bool setSurface(SDL_Surface* newSurface);
+    bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
+    bool setTexture(GLuint texture);
 
-    protected:
-      bool setSurface(SDL_Surface* newSurface);
-      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
-      bool setTexture(GLuint texture) { this->texture = texture; };
+  private:
+    GLuint           texture;            //!< The Texture-ID of opengl from this Texture.
+    bool             bAlpha;             //!< if the texture has an alpha channel.
+    SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
+};
 
-    private:
-      GLuint           texture;            //!< The Texture-ID of opengl from this Texture.
-      bool             bAlpha;             //!< if the texture has an alpha channel.
-      SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
-      GLclampf         priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
 
-      static bool      texturesEnabled;    //!< If the Textures are enabled.
-  };
+//! A Class, that reads in Textures from different fileformats.
+class Texture : public BaseObject
+{
+public:
+
+public:
+  Texture(GLenum target = GL_TEXTURE_2D);
+  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
+  Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+
+  virtual ~Texture();
+
+  bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
+  bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+  virtual bool rebuild();
+
+  /** @returns The textureID of this texture.  */
+  inline GLuint getTexture() const { return this->data->getTexture(); };
+  /** @returns true if texture has alpha, false otherwise */
+  inline bool hasAlpha() const  { return this->data->hasAlpha(); }
+  /** @returns the stored image of this Texture */
+  const SDL_Surface* const getStoredImage() const { return this->data->getStoredImage(); };
+
+
+
+  static void setTextureEnableState(bool texturesEnabled);
+  /** @returns true if Textures are enabled */
+  inline static bool getTextureEnableState() { return Texture::texturesEnabled; };
+  // Utility functionality:
+  static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
+  static GLuint loadTexToGL (const SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
+
+protected:
+  bool setSurface(SDL_Surface* newSurface) { return this->data->setSurface(newSurface); };
+  bool setAlpha(bool hasAlpha) { return this->data->setAlpha(hasAlpha); };
+  bool setTexture(GLuint texture) { return this->data->setTexture(texture); };
+
+private:
+  void init();
+  static void generateTexture(GLuint& texture, GLenum target);
+
+private:
+  CountPointer<TextureData>     data;               //!< The TextureData
+  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
+
+  static bool                   texturesEnabled;    //!< If the Textures are enabled.
+};
 
 #endif /* _TEXTURE_H */
Index: /trunk/src/lib/graphics/shader.h
===================================================================
--- /trunk/src/lib/graphics/shader.h	(revision 7784)
+++ /trunk/src/lib/graphics/shader.h	(revision 7785)
@@ -47,4 +47,7 @@
   inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
 
+  GLhandleARB getProgram() { return this->shaderProgram; }
+  GLhandleARB getVertexS() { return this->vertexShader; }
+  GLhandleARB getFragmentS() { return this->fragmentShader; }
 
   void printError(GLhandleARB program);
Index: /trunk/src/lib/util/executor/functor_list.h
===================================================================
--- /trunk/src/lib/util/executor/functor_list.h	(revision 7784)
+++ /trunk/src/lib/util/executor/functor_list.h	(revision 7785)
@@ -141,4 +141,6 @@
   FUNCTOR_LIST(3)(l_STRING, l_FLOAT, l_UINT);
   FUNCTOR_LIST(4)(l_STRING, l_FLOAT, l_UINT, l_UINT);
+  FUNCTOR_LIST(3)(l_STRING, l_INT, l_UINT);
+  FUNCTOR_LIST(3)(l_STRING, l_UINT, l_UINT);
 
 #endif /* FUNCTOR_LIST */
Index: /trunk/src/story_entities/game_world.cc
===================================================================
--- /trunk/src/story_entities/game_world.cc	(revision 7784)
+++ /trunk/src/story_entities/game_world.cc	(revision 7785)
@@ -33,4 +33,5 @@
 #include "terrain.h"
 #include "playable.h"
+#include "environments/mapped_water.h"
 
 #include "light.h"
@@ -443,8 +444,11 @@
 void GameWorld::display ()
 {
-  // clear buffer
-  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
-  // draw world
-  this->draw();
+  // render the reflection texture
+  this->renderPassReflection();
+  // redner the refraction texture
+  this->renderPassRefraction();
+  // render all
+  this->renderPassAll();
+
   // flip buffers
   GraphicsEngine::swapBuffers();
@@ -464,9 +468,58 @@
 }
 
-/**
- * @brief runs through all entities calling their draw() methods
- */
-void GameWorld::draw ()
-{
+
+
+/**
+ * reflection rendering for water surfaces
+ */
+void GameWorld::renderPassReflection()
+{
+    // clear buffer
+  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+  glLoadIdentity();
+
+  const std::list<BaseObject*>* reflectedWaters;
+  MappedWater* mw;
+
+  if( (reflectedWaters = ClassList::getList(CL_MAPPED_WATER)) != NULL)
+  {
+    std::list<BaseObject*>::const_iterator it;
+    for (it = reflectedWaters->begin(); it != reflectedWaters->end(); it++)
+    {
+      mw =  dynamic_cast<MappedWater*>(*it);
+
+      // prepare for reflection rendering
+      mw->activateReflection();
+
+      //camera and light
+      this->dataTank->localCamera->apply ();
+      this->dataTank->localCamera->project ();
+      LightManager::getInstance()->draw();
+      // draw everything to be included in the reflection
+      for (unsigned int i = 0; i < this->dataTank->drawLists.size(); ++i)
+        this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
+
+      // clean up from reflection rendering
+      mw->deactivateReflection();
+    }
+  }
+
+}
+
+
+/**
+ *  refraction rendering for water surfaces
+ */
+void GameWorld::renderPassRefraction()
+{}
+
+
+/**
+ *  this render pass renders the whole wolrd
+ */
+void GameWorld::renderPassAll()
+{
+  // clear buffer
+  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   GraphicsEngine* engine = GraphicsEngine::getInstance();
 
@@ -498,4 +551,5 @@
 }
 
+
 /**
  *  shows the loading screen
Index: /trunk/src/story_entities/game_world.h
===================================================================
--- /trunk/src/story_entities/game_world.h	(revision 7784)
+++ /trunk/src/story_entities/game_world.h	(revision 7785)
@@ -71,5 +71,9 @@
 
     void drawEntityList(const ObjectManager::EntityList& drawList ) const;
-    virtual void draw();
+    virtual void renderPassReflection();
+    virtual void renderPassRefraction();
+    virtual void renderPassAll();
+
+
     virtual void display();
 
Index: /trunk/src/util/object_manager.cc
===================================================================
--- /trunk/src/util/object_manager.cc	(revision 7784)
+++ /trunk/src/util/object_manager.cc	(revision 7785)
@@ -64,4 +64,8 @@
     while(!this->objectLists[i].empty())
       delete this->objectLists[i].front();
+
+  // delete reflectin list
+  while( !this->reflectionList.empty())
+    delete this->reflectionList.front();
 }
 
Index: /trunk/src/util/object_manager.h
===================================================================
--- /trunk/src/util/object_manager.h	(revision 7784)
+++ /trunk/src/util/object_manager.h	(revision 7785)
@@ -94,4 +94,14 @@
   static const char* OMListToString(OM_LIST omList);
 
+
+  void toReflectionList( WorldEntity* entity) { this->reflectionList.push_back(entity); }
+  /** @returns the list of all reflected objects in the world */
+  EntityList& getReflectionList() { return this->reflectionList; }
+  /** @returns the static list of all reflected objects in the world */
+  const EntityList& getReflectionList() const { return this->reflectionList; }
+
+
+
+
 private:
   const std::list<BaseObject>*            pNodeList;                //!< The List of PNodes.
@@ -100,4 +110,6 @@
 
   static const char*                      objectManagerListNames[]; //!< Names of all the lists
+
+  EntityList                              reflectionList;           //!< A list of all reflected objects in the world
 };
 
Index: /trunk/src/world_entities/WorldEntities.am
===================================================================
--- /trunk/src/world_entities/WorldEntities.am	(revision 7784)
+++ /trunk/src/world_entities/WorldEntities.am	(revision 7785)
@@ -1,99 +1,101 @@
 ## THE SUBCLASSES. THESE MUST BE DYNAMICALLY LINKED OR COMPILED IN DIRECTLY
 WorldEntities_SOURCES_ = \
-		world_entities/npcs/npc_test1.cc \
-		world_entities/npcs/npc_test.cc \
-		world_entities/npcs/ground_turret.cc \
-		\
-		world_entities/environment.cc \
-		world_entities/skysphere.cc \
-		world_entities/skybox.cc \
-		world_entities/terrain.cc \
-		world_entities/satellite.cc \
-		world_entities/movie_entity.cc \
-		world_entities/recorder.cc \
-		world_entities/character_attributes.cc \
-		world_entities/test_entity.cc \
-		world_entities/planet.cc \
-		\
-		world_entities/weapons/test_gun.cc \
-		world_entities/weapons/turret.cc \
-		world_entities/weapons/aiming_turret.cc \
-		world_entities/weapons/targeting_turret.cc \
-		world_entities/weapons/cannon.cc \
-		world_entities/weapons/hyperblaster.cc \
-		world_entities/weapons/aim.cc \
-		\
-		world_entities/projectiles/bomb.cc \
-		world_entities/projectiles/laser.cc \
-		world_entities/projectiles/test_bullet.cc \
-		world_entities/projectiles/rocket.cc \
-		world_entities/projectiles/guided_missile.cc \
-		world_entities/projectiles/hyperblast.cc \
-		\
-		world_entities/power_ups/turret_power_up.cc \
-		world_entities/power_ups/laser_power_up.cc \
-		\
-		world_entities/space_ships/space_ship.cc \
-		world_entities/space_ships/helicopter.cc \
-		world_entities/space_ships/hover.cc \
-		world_entities/space_ships/turbine_hover.cc \
-		world_entities/creatures/md2_creature.cc \
-		\
-		\
-		world_entities/environments/water.cc \
-		world_entities/environments/model_entity.cc \
-		world_entities/environments/building.cc \
-		\
-		world_entities/elements/image_entity.cc \
-		world_entities/elements/text_element.cc \
-		\
-		world_entities/effects/lightning_bolt.cc
+                world_entities/npcs/npc_test1.cc \
+                world_entities/npcs/npc_test.cc \
+                world_entities/npcs/ground_turret.cc \
+                \
+                world_entities/environment.cc \
+                world_entities/skysphere.cc \
+                world_entities/skybox.cc \
+                world_entities/terrain.cc \
+                world_entities/satellite.cc \
+                world_entities/movie_entity.cc \
+                world_entities/recorder.cc \
+                world_entities/character_attributes.cc \
+                world_entities/test_entity.cc \
+                world_entities/planet.cc \
+                \
+                world_entities/weapons/test_gun.cc \
+                world_entities/weapons/turret.cc \
+                world_entities/weapons/aiming_turret.cc \
+                world_entities/weapons/targeting_turret.cc \
+                world_entities/weapons/cannon.cc \
+                world_entities/weapons/hyperblaster.cc \
+                world_entities/weapons/aim.cc \
+                \
+                world_entities/projectiles/bomb.cc \
+                world_entities/projectiles/laser.cc \
+                world_entities/projectiles/test_bullet.cc \
+                world_entities/projectiles/rocket.cc \
+                world_entities/projectiles/guided_missile.cc \
+                world_entities/projectiles/hyperblast.cc \
+                \
+                world_entities/power_ups/turret_power_up.cc \
+                world_entities/power_ups/laser_power_up.cc \
+                \
+                world_entities/space_ships/space_ship.cc \
+                world_entities/space_ships/helicopter.cc \
+                world_entities/space_ships/hover.cc \
+                world_entities/space_ships/turbine_hover.cc \
+                world_entities/creatures/md2_creature.cc \
+                \
+                \
+                world_entities/environments/water.cc \
+                world_entities/environments/model_entity.cc \
+                world_entities/environments/building.cc \
+                world_entities/environments/mapped_water.cc \
+                \
+                world_entities/elements/image_entity.cc \
+                world_entities/elements/text_element.cc \
+                \
+                world_entities/effects/lightning_bolt.cc
 
 
 WorldEntities_HEADERS_ = \
-		npcs/npc_test.h \
-		npcs/npc_test1.h \
-		npcs/ground_turret.h \
-		environment.h \
-		skysphere.h \
-		skybox.h \
-		terrain.h \
-		satellite.h \
-		movie_entity.h \
-		recorder.h \
-		character_attributes.h \
-		test_entity.h \
-		planet.h \
-		\
-		weapons/test_gun.h \
-		weapons/cannon.h \
-		weapons/hyperblaster.h \
-		weapons/turret.h \
-		weapons/aiming_turret.h \
-		weapons/targeting_turret.h \
-		weapons/aim.h \
-		\
-		projectiles/bomb.h \
-		projectiles/laser.h \
-		projectiles/test_bullet.h \
-		projectiles/rocket.h \
-		projectiles/guided_missile.h \
-		projectiles/hyperblast.h \
-		\
-		power_ups/turret_power_up.h \
-		power_ups/laser_power_up.h \
-		\
-		space_ships/space_ship.h \
-		space_ships/helicopter.h \
-		space_ships/hover.h \
-		space_ships/turbine_hover.h \
-		creatures/md2_creature.h \
-		\
-		environments/water.h \
-		environments/model_entity.h \
-		environments/building.h \
-		\
-		elements/image_entity.h \
-		elements/text_element.h \
-		\
-		effects/lightning_bolt.h
+                npcs/npc_test.h \
+                npcs/npc_test1.h \
+                npcs/ground_turret.h \
+                environment.h \
+                skysphere.h \
+                skybox.h \
+                terrain.h \
+                satellite.h \
+                movie_entity.h \
+                recorder.h \
+                character_attributes.h \
+                test_entity.h \
+                planet.h \
+                \
+                weapons/test_gun.h \
+                weapons/cannon.h \
+                weapons/hyperblaster.h \
+                weapons/turret.h \
+                weapons/aiming_turret.h \
+                weapons/targeting_turret.h \
+                weapons/aim.h \
+                \
+                projectiles/bomb.h \
+                projectiles/laser.h \
+                projectiles/test_bullet.h \
+                projectiles/rocket.h \
+                projectiles/guided_missile.h \
+                projectiles/hyperblast.h \
+                \
+                power_ups/turret_power_up.h \
+                power_ups/laser_power_up.h \
+                \
+                space_ships/space_ship.h \
+                space_ships/helicopter.h \
+                space_ships/hover.h \
+                space_ships/turbine_hover.h \
+                creatures/md2_creature.h \
+                \
+                environments/water.h \
+                environments/model_entity.h \
+                environments/building.h \
+                environments/mapped_water.h \
+                \
+                elements/image_entity.h \
+                elements/text_element.h \
+                \
+                effects/lightning_bolt.h
