Index: trunk/src/lib/graphics/importer/material.cc
===================================================================
--- trunk/src/lib/graphics/importer/material.cc	(revision 8035)
+++ trunk/src/lib/graphics/importer/material.cc	(revision 8037)
@@ -108,4 +108,16 @@
       return true;
 
+/// !!  HACK !!! FIX THIS IN MODEL ///
+  else if (likely(Material::selectedMaterial != NULL))
+  {
+  Material::unselect();
+//     for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
+//     {
+//         glActiveTexture(Material::glTextureArbs[i]);
+//         glBindTexture(GL_TEXTURE_2D, 0);
+//         glDisable(GL_TEXTURE_2D);
+//     }
+  }
+
   if (likely(Material::selectedMaterial != NULL))
   {
@@ -146,5 +158,4 @@
     glShadeModel(GL_SMOOTH);
 
-
   for(unsigned int i = 0; i < this->textures.size(); ++i)
   {
@@ -160,4 +171,15 @@
 }
 
+void Material::unselect()
+{
+  Material::selectedMaterial = NULL;
+    for(unsigned int i = 0; i < 8; ++i)
+    {
+        glActiveTexture(Material::glTextureArbs[i]);
+        glBindTexture(GL_TEXTURE_2D, 0);
+        glDisable(GL_TEXTURE_2D);
+    }
+}
+
 /**
  *  Sets the Material Illumination Model.
@@ -366,9 +388,23 @@
 }
 
+/**
+ * @brief renders viewport buffer (?? or another buffer ;-)) to a texture
+ * @param textureNumber select the texture unit that will be overwritten
+*/
+void Material::renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
+{
+  assert(textureNumber < Material::getMaxTextureUnits());
+  assert(textureNumber < this->textures.size());
+
+  glActiveTexture(0);
+   glEnable(GL_TEXTURE_2D);
+   glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
+  glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
+
+}
 
 /**
  * @brief Sets the Materials Ambient Map
- * @param aMap the Name of the Image to Use
-   @todo implement this
+ * @todo implement this
 */
 void Material::setAmbientMap(const std::string& aMap, GLenum target)
Index: trunk/src/lib/graphics/importer/material.h
===================================================================
--- trunk/src/lib/graphics/importer/material.h	(revision 8035)
+++ trunk/src/lib/graphics/importer/material.h	(revision 8037)
@@ -30,4 +30,6 @@
 
     bool select () const;
+    bool activateTextureUnit(unsigned int textureNumber);
+    static void unselect();
 
     void setIllum (int illum);
@@ -55,4 +57,5 @@
     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 renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
 
     void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
Index: trunk/src/lib/graphics/shader.cc
===================================================================
--- trunk/src/lib/graphics/shader.cc	(revision 8035)
+++ trunk/src/lib/graphics/shader.cc	(revision 8037)
@@ -20,5 +20,7 @@
 #include "stdlibincl.h"
 #include "compiler.h"
-#include <stdio.h>
+//#include <stdio.h>
+#include <fstream>
+
 #include "debug.h"
 
@@ -26,6 +28,6 @@
 
 
-#ifndef PARSELINELENGHT
-#define PARSELINELENGHT     512       //!< how many chars to read at once
+#ifndef PARSELINELENGTH
+#define PARSELINELENGTH     512       //!< how many chars to read at once
 #endif
 
@@ -40,6 +42,4 @@
    this->setClassID(CL_SHADER, "Shader");
 
-   this->fragmentShaderFile = "";
-   this->vertexShaderFile = "";
    this->shaderProgram = 0;
    this->vertexShader = 0;
@@ -48,17 +48,13 @@
    if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)
      {
-       GLint status = 0;
-
        this->shaderProgram = glCreateProgramObjectARB();
 
        if (!vertexShaderFile.empty())
-         this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
+         this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);
        if (!fragmentShaderFile.empty())
-         this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
-       glLinkProgramARB(this->shaderProgram);
-       // link error checking
-       glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
-       if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
-         this->printError(this->shaderProgram);
+         this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);
+
+       this->linkShaderProgram();
+
     }
    else
@@ -78,6 +74,6 @@
 
   // delete what has to be deleted here
-  this->deleteProgram(SHADER_VERTEX);
-  this->deleteProgram(SHADER_FRAGMENT);
+  this->deleteProgram(Shader::Vertex);
+  this->deleteProgram(Shader::Fragment);
 
   if (this->fragmentShader != 0)
@@ -116,16 +112,18 @@
 
 
-bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName)
+bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName)
 {
   GLhandleARB shader = 0;
 
-  if (type != SHADER_VERTEX && type != SHADER_FRAGMENT)
+  if (type != Shader::Vertex && type != Shader::Fragment)
     return false;
   this->deleteProgram(type);
 
 
-  std::vector<char*>* program = fileReadArray(fileName);
-
-  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
+  std::string program;
+  if (!readShader(fileName, program))
+    return false;
+
+  if (type == Shader::Vertex && GLEW_ARB_vertex_shader)
   {
     this->vertexShaderFile = fileName;
@@ -134,5 +132,5 @@
   }
 
-  if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
+  if (type == Shader::Fragment && GLEW_ARB_fragment_shader)
   {
     this->fragmentShaderFile = fileName;
@@ -144,6 +142,7 @@
   {
     GLint status = 0;
-    /// FIXME do it back
-    //    glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL);
+    const char* prog = program.c_str();
+
+    glShaderSourceARB(shader, 1, &prog, NULL);
     glCompileShaderARB(shader);
     // checking on error.
@@ -154,57 +153,39 @@
       glAttachObjectARB(this->shaderProgram, shader);
   }
-  for (unsigned int i=0; i< program->size(); i++)
-    delete[] (*program)[i];
-  delete program;
-}
-
-char* Shader::fileRead(const std::string& fileName)
-{
-  FILE* fileHandle;
-  char* content = NULL;
-
-  int count = 0;
-
-  if (fileName.empty())
-    return NULL;
-
-  fileHandle = fopen(fileName.c_str(), "rt");
-
-  if (fileHandle == NULL)
-    return NULL;
-  fseek(fileHandle, 0, SEEK_END);
-  count = ftell(fileHandle);
-  rewind(fileHandle);
-  if (count > 0) {
-     content = new char[count+1];
-     count = fread(content, sizeof(char), count, fileHandle);
-     content[count] = '\0';
-   }
-   fclose(fileHandle);
- return content;
-}
-
-
-std::vector<char*>* Shader::fileReadArray(const std::string& fileName)
-{
-  FILE*    stream;           //< The stream we use to read the file.
-
-  if( (stream = fopen (fileName.c_str(), "rt")) == NULL)
-  {
-    PRINTF(1)("Shader could not open %s\n", fileName.c_str());
-    return NULL;
-  }
-  std::vector<char*>* file = new std::vector<char*>;
-
-  char lineBuffer[PARSELINELENGHT];
-  char* addString;
-  while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL)
-  {
-    addString = new char[strlen(lineBuffer)+1];
-    strcpy(addString, lineBuffer);
-    file->push_back(addString);
-  }
-  fclose(stream);
-  return file;
+}
+
+
+void Shader::linkShaderProgram()
+{
+  GLint status = 0;
+
+  glLinkProgramARB(this->shaderProgram);
+       // link error checking
+  glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status);
+  if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION)
+    this->printError(this->shaderProgram);
+}
+
+
+bool Shader::readShader(const std::string& fileName, std::string& output)
+{
+  char lineBuffer[PARSELINELENGTH];
+
+  std::ifstream shader;
+  shader.open(fileName.c_str());
+  if (!shader.is_open())
+    return false;
+
+
+  while (!shader.eof())
+  {
+    shader.getline(lineBuffer, PARSELINELENGTH);
+    output += lineBuffer;
+    output += "\n";
+  }
+
+
+  shader.close();
+  return true;
 }
 
@@ -228,8 +209,8 @@
 
 
-void Shader::deleteProgram(SHADER_TYPE type)
+void Shader::deleteProgram(Shader::Type type)
 {
   GLint status = 0;
-  if (type == SHADER_VERTEX && this->vertexShader != 0)
+  if (type == Shader::Vertex && this->vertexShader != 0)
   {
     this->vertexShaderFile = "";
@@ -241,5 +222,5 @@
     this->vertexShader = 0;
   }
-  else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
+  else if (type == Shader::Fragment && this->fragmentShader != 0)
   {
     this->fragmentShaderFile = "";
Index: trunk/src/lib/graphics/shader.h
===================================================================
--- trunk/src/lib/graphics/shader.h	(revision 8035)
+++ trunk/src/lib/graphics/shader.h	(revision 8037)
@@ -12,19 +12,80 @@
 
 
-typedef enum
-{
-  SHADER_NONE       = 0,
-  SHADER_FRAGMENT   = 1,
-  SHADER_VERTEX     = 0,
-
-} SHADER_TYPE;
-
 // FORWARD DECLARATION
 
 
+
 //! A class for ...
-class Shader : public BaseObject {
+class Shader : public BaseObject
+{
+public:
+  class Uniform
+  {
+  public:
+    Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
+    Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
+    Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
 
-  public:
+    void set(float v0) const { glUniform1f(this->uniform, v0); }
+    void set(float v0, float v1) const { glUniform2f(this->uniform, v0, v1); }
+    void set(float v0, float v1, float v2) const { glUniform3f(this->uniform, v0, v1, v2); }
+    void set(float v0, float v1, float v2, float v3) const { glUniform4f(this->uniform, v0, v1, v2, v3); }
+
+    void set(int v0) const { glUniform1i(this->uniform, v0); }
+    void set(int v0, int v1) const { glUniform2i(this->uniform, v0, v1); }
+    void set(int v0, int v1, int v2) const { glUniform3i(this->uniform, v0, v1, v2); }
+    void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); }
+
+    void setV(unsigned int count, float* vv) const
+    {
+      switch (count)
+      {
+        case 1:
+          glUniform1fv(this->uniform, 1, vv);
+          break;
+        case 2:
+          glUniform2fv(this->uniform, 2, vv);
+          break;
+        case 3:
+          glUniform3fv(this->uniform, 3, vv);
+          break;
+        case 4:
+          glUniform4fv(this->uniform, 4, vv);
+          break;
+      }
+    }
+    void setV(unsigned int count, int* vv) const
+    {
+      switch (count)
+      {
+        case 1:
+          glUniform1iv(this->uniform, 1, vv);
+          break;
+        case 2:
+          glUniform2iv(this->uniform, 2, vv);
+          break;
+        case 3:
+          glUniform3iv(this->uniform, 3, vv);
+          break;
+        case 4:
+          glUniform4iv(this->uniform, 4, vv);
+          break;
+      }
+    }
+    private:
+    GLint uniform;
+  };
+
+  typedef enum
+  {
+    None       = 0,
+    Fragment   = 1,
+    Vertex     = 2,
+
+    Program    = 4,
+  }
+  Type;
+
+public:
   Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
   virtual ~Shader();
@@ -32,36 +93,48 @@
   static bool unload(Shader* shader);
 
-  bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName);
+
+  static bool checkShaderAbility();
   void activateShader();
   static void deactivateShader();
-  void deleteProgram(SHADER_TYPE type);
 
-  char* fileRead(const std::string& fileName);
-  std::vector<char*>* fileReadArray(const std::string& fileName);
+  Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); }
 
-  static bool checkShaderAbility();
+  bool loadShaderProgramm(Shader::Type type, const std::string& fileName);
+  void deleteProgram(Shader::Type type);
 
-  inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
+  void linkShaderProgram();
+
+
+  bool readShader(const std::string& fileName, std::string& output);
+
+
+inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; };
   inline static Shader* getActiveShader() { return Shader::storedShader; };
   inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
   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);
+
+
+  GLhandleARB getProgram() const { return this->shaderProgram; }
+  GLhandleARB getVertexS() const { return this->vertexShader; }
+  GLhandleARB getFragmentS() const { return this->fragmentShader; }
+
   void debug() const;
 
-  private:
+  static void printError(GLhandleARB program);
 
- private:
-   std::string            fragmentShaderFile;
-   std::string            vertexShaderFile;
-   GLhandleARB            shaderProgram;
-   GLhandleARB            vertexShader;
-   GLhandleARB            fragmentShader;
 
-   static Shader*         storedShader;
+private:
+  std::string            fragmentShaderFile;
+  std::string            vertexShaderFile;
+
+  GLhandleARB            shaderProgram;
+
+  GLhandleARB            vertexShader;
+  GLhandleARB            fragmentShader;
+
+
+  static Shader*         storedShader;
 };
 
Index: trunk/src/lib/graphics/text_engine/text.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/text.cc	(revision 8035)
+++ trunk/src/lib/graphics/text_engine/text.cc	(revision 8037)
@@ -225,4 +225,8 @@
   // setting the Blending effects
   glColor4f(this->color.x, this->color.y, this->color.z, this->blending);
+
+
+  glActiveTexture(GL_TEXTURE0);
+
   glEnable(GL_BLEND);
   glEnable(GL_TEXTURE_2D);
