Index: trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- trunk/src/lib/graphics/importer/texture.cc	(revision 5701)
+++ trunk/src/lib/graphics/importer/texture.cc	(revision 5753)
@@ -37,4 +37,5 @@
   this->bAlpha = false;
   this->texture = 0;
+  this->image = NULL;
   if (imageName != NULL)
     this->loadImage(imageName);
@@ -50,92 +51,8 @@
   if (this->texture != 0)
     glDeleteTextures(1, &this->texture);
+  if (this->image != NULL)
+    SDL_FreeSurface(this->image);
 }
 
-/**
- *  Loads a Texture to the openGL-environment.
- * @param surface the Image to load to openGL
- * @returns The ID of the texture.
-*/
-GLuint Texture::loadTexToGL (SDL_Surface* surface)
-{
-  if (GraphicsEngine::texturesEnabled)
-    {
-      PRINTF(4)("Loading texture to OpenGL-Environment.\n");
-
-      int w, h;
-      SDL_Surface *image;
-      SDL_Rect area;
-      Uint32 saved_flags;
-      Uint8  saved_alpha;
-
-      w = surface->w;
-      h = surface->h;
-
-      image = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                                   w, h,
-                                   32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
-                                   0x000000FF,
-                                   0x0000FF00,
-                                   0x00FF0000,
-                                   0xFF000000
-#else
-                                   0xFF000000,
-                                   0x00FF0000,
-                                   0x0000FF00,
-                                   0x000000FF
-#endif
-                                   );
-      if ( image == NULL ) {
-        return 0;
-      }
-
-      /* Save the alpha blending attributes */
-      saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
-      saved_alpha = surface->format->alpha;
-      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
-        SDL_SetAlpha(surface, 0, 0);
-      }
-
-      /* Copy the surface into the GL texture image */
-      area.x = 0;
-      area.y = 0;
-      area.w = surface->w;
-      area.h = surface->h;
-      SDL_BlitSurface(surface, &area, image, &area);
-
-      /* Restore the alpha blending attributes */
-      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
-        SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
-        this->bAlpha = true;
-      }
-
-      /* Create an OpenGL texture for the image */
-      glGenTextures(1, &this->texture);
-      glBindTexture(GL_TEXTURE_2D, this->texture);
-      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-      // build the Texture
-      glTexImage2D(GL_TEXTURE_2D,
-                   0,
-                   GL_RGBA,
-                   w, h,
-                   0,
-                   GL_RGBA,
-                   GL_UNSIGNED_BYTE,
-                   image->pixels);
-      // build the MipMaps
-      gluBuild2DMipmaps(GL_TEXTURE_2D,
-                        GL_RGBA,
-                        w,
-                        h,
-                        GL_RGBA,
-                        GL_UNSIGNED_BYTE,
-                        image->pixels);
-
-      SDL_FreeSurface(image); /* No longer needed */
-      glBindTexture(GL_TEXTURE_2D, 0);
-    }
-}
 
 /**
@@ -154,5 +71,13 @@
           // load the new Image to memory
           tmpSurf = IMG_Load(imageName);
-          if(tmpSurf == NULL)
+          if(tmpSurf != NULL)
+          {
+            PRINTF(3)("loading Image %s\n", imageName);
+	    this->image = this->prepareSurface(tmpSurf);
+            this->texture = loadTexToGL(this->image);
+            SDL_FreeSurface(tmpSurf);
+            return true;
+          }
+          else
             {
               PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
@@ -160,11 +85,4 @@
               return false;
             }
-          else
-          {
-            PRINTF(3)("loading Image %s\n", imageName);
-            loadTexToGL(tmpSurf);
-            SDL_FreeSurface(tmpSurf);
-            return true;
-          }
         }
       else
@@ -175,2 +93,88 @@
     return false;
 }
+
+SDL_Surface* Texture::prepareSurface(SDL_Surface* surface)
+{
+  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
+  
+  SDL_Surface *image;
+  SDL_Rect area;
+  Uint32 saved_flags;
+  Uint8  saved_alpha;
+  
+  image = SDL_CreateRGBSurface(SDL_SWSURFACE,
+			       surface->w, surface->h,
+			       32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
+			       0x000000FF,
+			       0x0000FF00,
+			       0x00FF0000,
+			       0xFF000000
+#else
+			       0xFF000000,
+			       0x00FF0000,
+			       0x0000FF00,
+			       0x000000FF
+#endif
+			       );
+  if ( image == NULL ) {
+    return 0;
+  }
+  
+  /* Save the alpha blending attributes */
+  saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+  saved_alpha = surface->format->alpha;
+  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+    SDL_SetAlpha(surface, 0, 0);
+  }
+  
+  /* Copy the surface into the GL texture image */
+  area.x = 0;
+  area.y = 0;
+  area.w = surface->w;
+  area.h = surface->h;
+  SDL_BlitSurface(surface, &area, image, &area);
+  
+  /* Restore the alpha blending attributes */
+  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) 
+    {
+      SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
+      this->bAlpha = true;
+    }
+  return image;
+}
+
+
+/**
+ *  Loads a Texture to the openGL-environment.
+ * @param surface the Image to load to openGL
+ * @returns The ID of the texture.
+ */
+GLuint Texture::loadTexToGL (SDL_Surface* surface) const
+{
+  GLuint texture = 0;
+  /* Create an OpenGL texture for the image */
+  glGenTextures(1, &texture);
+  glBindTexture(GL_TEXTURE_2D, texture);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+  // build the Texture
+  glTexImage2D(GL_TEXTURE_2D,
+	       0,
+	       GL_RGBA,
+	       surface->w, surface->h,
+	       0,
+	       GL_RGBA,
+	       GL_UNSIGNED_BYTE,
+	       surface->pixels);
+  // build the MipMaps
+  gluBuild2DMipmaps(GL_TEXTURE_2D,
+		    GL_RGBA,
+		    surface->w,
+		    surface->h,
+		    GL_RGBA,
+		    GL_UNSIGNED_BYTE,
+		    surface->pixels);
+  glBindTexture(GL_TEXTURE_2D, 0);
+  return texture;
+}
Index: trunk/src/lib/graphics/importer/texture.h
===================================================================
--- trunk/src/lib/graphics/importer/texture.h	(revision 5701)
+++ trunk/src/lib/graphics/importer/texture.h	(revision 5753)
@@ -26,19 +26,22 @@
   Texture(const char* imageName = NULL);
   //  Texture(TEXTURE_TYPE type, int resolution);
+  ~Texture();
 
-  ~Texture();
+  bool loadImage(const char* imageName);
+  bool reload();
 
   /** @returns The textureID of this texture.  */
   inline GLuint getTexture() const { return this->texture; };
-  GLuint loadTexToGL (SDL_Surface* surface);
   /** @returns true if texture has alpha, false otherwise */
   inline bool hasAlpha() const {return bAlpha;}
 
-  bool loadImage(const char* imageName);
-
+ private:
+  SDL_Surface* prepareSurface(SDL_Surface* input);
+  GLuint loadTexToGL (SDL_Surface* surface) const;
 
  private:
-  GLuint     texture;          //!< The Texture-ID of opengl from this Texture.
-  bool       bAlpha;           //!< if the texture has an alpha channel.
+  GLuint        texture;            //!< The Texture-ID of opengl from this Texture.
+  bool          bAlpha;             //!< if the texture has an alpha channel.
+  SDL_Surface*  image;   
 };
 
