Index: /branches/water/src/world_entities/environments/mapped_water.cc
===================================================================
--- /branches/water/src/world_entities/environments/mapped_water.cc	(revision 7780)
+++ /branches/water/src/world_entities/environments/mapped_water.cc	(revision 7781)
@@ -17,4 +17,5 @@
 #include "util/loading/load_param.h"
 #include "util/loading/factory.h"
+#include "util/loading/resource_manager.h"
 
 
@@ -25,5 +26,5 @@
 
 MappedWater::MappedWater(const TiXmlElement* root)
- : texture(GL_TEXTURE_2D)
+    : texture(GL_TEXTURE_2D)
 {
   this->setClassID(CL_MAPPED_WATER, "MappedWater");
@@ -38,8 +39,8 @@
   //mat.setDiffuseMap(&this->texture, 0);
   mat.setDiffuseMap("pictures/dudvmap.bmp", GL_TEXTURE_2D, 0);
-  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
+/*  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 1);
   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 2);
   mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 3);
-  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);
+  mat.setDiffuseMap("pictures/sky-replace.jpg", GL_TEXTURE_2D, 4);*/
   // load refraction texture
   //mat.setDiffuseMap(&this->refractionTexture, 1);
@@ -50,14 +51,39 @@
   // set up depth texture
   //mat.setDiffuseMap(&this->depthTexture, 4);
-  
+
   // set the size of the refraction and reflection textures
+
+
+
+  /// MAKE THE MAPPING TEXTURE.
+  // THIS IS A HACK AND SHOULD BE IN TEXTURE SOMEWHERE.
   this->textureSize = 512;
-
-  shader = new Shader("/home/lieni/orxonox/data/trunk/shaders/water.vert", "/home/lieni/orxonox/data/trunk/shaders/mapped_water.frag");
+  unsigned int channels = 32;
+  GLenum type = GL_RGBA;
+  unsigned int* pTexture = new unsigned int [this->textureSize * this->textureSize * channels];
+  memset(pTexture, 0, this->textureSize * this->textureSize * channels * sizeof(unsigned int));
+  // Register the texture with OpenGL and bind it to the texture ID
+  mat.select();
+  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
+  printf("========= CREATE %d\n", this->texture.getTexture());
+
+  // Create the texture and store it on the video card
+  glTexImage2D(GL_TEXTURE_2D, 0, channels, this->textureSize, this->textureSize, 0, type, GL_UNSIGNED_INT, pTexture);
+
+  // 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);
+
+  // Since we stored the texture space with OpenGL, we can delete the image data
+  delete [] pTexture;
+
+  //  shader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/water.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/mapped_water.frag");
 }
 
 MappedWater::~MappedWater()
 {
-  delete shader;
+  //delete shader;
 }
 
@@ -90,10 +116,12 @@
 
   mat.select();
+  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
+
   // Shader init
-  this->shader->activateShader();
+  //this->shader->activateShader();
   GLint uniform;
-  
+
   // Set the variable "reflection" to correspond to the first texture unit
-  uniform = glGetUniformLocationARB(shader->getProgram(), "reflection"); 
+  uniform = glGetUniformLocationARB(shader->getProgram(), "reflection");
   glUniform1iARB(uniform, 0); //second paramter is the texture unit
 
@@ -108,15 +136,15 @@
 
   // Set the variable "dudvMap" to correspond to the fourth texture unit
-  uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap"); 
+  uniform = glGetUniformLocationARB(shader->getProgram(), "dudvMap");
   glUniform1iARB(uniform, 3);
 
   // Set the variable "depthMap" to correspond to the fifth texture unit
   //uniform = glGetUniformLocationARB(shader->getProgram(), "depthMap");
-  //glUniform1iARB(uniform, 4); 
+  //glUniform1iARB(uniform, 4);
   // FIXME we dont have a depthMap yet :-(
 
   // Give the variable "waterColor" a blue color
   uniform = glGetUniformLocationARB(shader->getProgram(), "waterColor");
-  glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f); 
+  glUniform4fARB(uniform, 0.1f, 0.2f, 0.4f, 1.0f);
 
   // FIXME set camera and light information
@@ -129,41 +157,41 @@
   // Give the variable "lightPos" our hard coded light position
   uniform = glGetUniformLocationARB(shader->getProgram(), "lightPos");
-  glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f); 
+  glUniform4fARB(uniform, lightPos.x, lightPos.y, lightPos.z, 1.0f);
 
   // Give the variable "cameraPos" our camera position
   uniform = glGetUniformLocationARB(shader->getProgram(), "cameraPos");
-  glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f); 
+  glUniform4fARB(uniform, vPosition.x, vPosition.y, vPosition.z, 1.0f);
 
   glBegin(GL_QUADS);
-    glNormal3f(0,1,0);
-    glMultiTexCoord2f(GL_TEXTURE0, 0,0);
-    glMultiTexCoord2f(GL_TEXTURE1, 0,0);
-    glMultiTexCoord2f(GL_TEXTURE2, 0,0);
-    glMultiTexCoord2f(GL_TEXTURE3, 0,0);
-    glMultiTexCoord2f(GL_TEXTURE4, 0,0);
-    glVertex3f(0,0,0);
-
-    glMultiTexCoord2f(GL_TEXTURE0, 1,0);
-    glMultiTexCoord2f(GL_TEXTURE1, 1,0);
-    glMultiTexCoord2f(GL_TEXTURE2, 1,0);
-    glMultiTexCoord2f(GL_TEXTURE3, 1,0);
-    glMultiTexCoord2f(GL_TEXTURE4, 1,0);
-    glVertex3f(100,0,0);
-
-    glMultiTexCoord2f(GL_TEXTURE0, 1,1);
-    glMultiTexCoord2f(GL_TEXTURE1, 1,1);
-    glMultiTexCoord2f(GL_TEXTURE2, 1,1);
-    glMultiTexCoord2f(GL_TEXTURE3, 1,1);
-    glMultiTexCoord2f(GL_TEXTURE4, 1,1);
-    glVertex3f(100,0,-100);
-
-    glMultiTexCoord2f(GL_TEXTURE0, 0,1);
-    glMultiTexCoord2f(GL_TEXTURE1, 0,1);
-    glMultiTexCoord2f(GL_TEXTURE2, 0,1);
-    glMultiTexCoord2f(GL_TEXTURE3, 0,1);
-    glMultiTexCoord2f(GL_TEXTURE4, 0,1);
-    glVertex3f(0,0,-100);
+  glNormal3f(0,1,0);
+  glMultiTexCoord2f(GL_TEXTURE0, 0,0);
+  glMultiTexCoord2f(GL_TEXTURE1, 0,0);
+  glMultiTexCoord2f(GL_TEXTURE2, 0,0);
+  glMultiTexCoord2f(GL_TEXTURE3, 0,0);
+  glMultiTexCoord2f(GL_TEXTURE4, 0,0);
+  glVertex3f(0,0,0);
+
+  glMultiTexCoord2f(GL_TEXTURE0, 1,0);
+  glMultiTexCoord2f(GL_TEXTURE1, 1,0);
+  glMultiTexCoord2f(GL_TEXTURE2, 1,0);
+  glMultiTexCoord2f(GL_TEXTURE3, 1,0);
+  glMultiTexCoord2f(GL_TEXTURE4, 1,0);
+  glVertex3f(100,0,0);
+
+  glMultiTexCoord2f(GL_TEXTURE0, 1,1);
+  glMultiTexCoord2f(GL_TEXTURE1, 1,1);
+  glMultiTexCoord2f(GL_TEXTURE2, 1,1);
+  glMultiTexCoord2f(GL_TEXTURE3, 1,1);
+  glMultiTexCoord2f(GL_TEXTURE4, 1,1);
+  glVertex3f(100,0,-100);
+
+  glMultiTexCoord2f(GL_TEXTURE0, 0,1);
+  glMultiTexCoord2f(GL_TEXTURE1, 0,1);
+  glMultiTexCoord2f(GL_TEXTURE2, 0,1);
+  glMultiTexCoord2f(GL_TEXTURE3, 0,1);
+  glMultiTexCoord2f(GL_TEXTURE4, 0,1);
+  glVertex3f(0,0,-100);
   glEnd();
-  this->shader->deactivateShader();
+  //this->shader->deactivateShader();
 
   glPopMatrix();
@@ -172,5 +200,4 @@
 void MappedWater::tick(float dt)
 {
-
 }
 
@@ -183,5 +210,5 @@
 {
   glPushAttrib(GL_VIEWPORT_BIT);
-//   glPushMatrix();
+  //   glPushMatrix();
 
   //glLoadIdentity();
@@ -199,26 +226,26 @@
   //if(g_Camera.Position().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};
-   //   glEnable(GL_CLIP_PLANE0);
-     // glClipPlane(GL_CLIP_PLANE0, plane);
-
-      // Render the world upside down and clipped (only render the top flipped).
-      // If we don't turn OFF caustics for the reflection texture we get horrible
-      // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
-      //RenderWorld(false);
-
-      // Turn clipping off
-     // glDisable(GL_CLIP_PLANE0);
-
-      // Restore back-face culling
-    //  glCullFace(GL_BACK);
+  // 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};
+  //   glEnable(GL_CLIP_PLANE0);
+  // glClipPlane(GL_CLIP_PLANE0, plane);
+
+  // Render the world upside down and clipped (only render the top flipped).
+  // If we don't turn OFF caustics for the reflection texture we get horrible
+  // artifacts in the water.  That is why we set bRenderCaustics to FALSE.
+  //RenderWorld(false);
+
+  // Turn clipping off
+  // glDisable(GL_CLIP_PLANE0);
+
+  // Restore back-face culling
+  //  glCullFace(GL_BACK);
   //}
   /*else
@@ -237,23 +264,21 @@
 void MappedWater::deactivateReflection()
 {
-  //glBindTexture(GL_TEXTURE_2D, texture.getTexture()); is done by mat.select();
+//  glBindTexture(GL_TEXTURE_2D, texture.getTexture()); //is done by mat.select();
+  glBindTexture(GL_TEXTURE_2D, this->mat.getDiffuseTexture(0));
 
   //mat.setDiffuseMap(&texture, 0);
-  
-  //mat.select();
-  //glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
+  // mat.select();
+  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureSize, textureSize);
 
 
   glPopAttrib();
-//   glPopMatrix();
+  //   glPopMatrix();
 }
 
 void MappedWater::activateRefraction()
 {
-
 }
 
 void MappedWater::deactivateRefraction()
 {
-
-}
+}
