Index: trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- trunk/src/lib/graphics/importer/texture.cc	(revision 5755)
+++ trunk/src/lib/graphics/importer/texture.cc	(revision 5768)
@@ -66,13 +66,13 @@
     {
       if (this->image != NULL)
-	{
-	  SDL_FreeSurface(this->image);
-	  this->image = NULL;
-	}
+        {
+          SDL_FreeSurface(this->image);
+          this->image = NULL;
+        }
       if (this->texture != 0)
-	{
-	  glDeleteTextures(1, &this->texture);
-	  this->texture = 0;
-	}
+        {
+          glDeleteTextures(1, &this->texture);
+          this->texture = 0;
+        }
       if (imageName != NULL)
         {
@@ -85,6 +85,6 @@
           {
             PRINTF(4)("loading Image %s\n", imageName);
-	    this->image = this->prepareSurface(tmpSurf);
-            this->texture = loadTexToGL(this->image);
+            if (this->prepareSurface(tmpSurf))
+              loadTexToGL();
             SDL_FreeSurface(tmpSurf);
             return true;
@@ -99,5 +99,5 @@
       else
         {
-	  PRINTF(2)("Image-Name not specified\n");
+          PRINTF(2)("Image-Name not specified\n");
           return false;
         }
@@ -117,7 +117,7 @@
     {
       PRINTF(4)("Reloading Texture %s\n", this->getName());
-      this->texture = this->loadTexToGL(this->image);
+      this->loadTexToGL();
     }
-  
+
 }
 
@@ -127,31 +127,34 @@
  * @returns a !!new!! Surface, that is loadable by openGL.
  */
-SDL_Surface* Texture::prepareSurface(SDL_Surface* surface)
+bool Texture::prepareSurface(SDL_Surface* surface)
 {
   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
-  
-  SDL_Surface *image;
+
+  SDL_Surface* putSurface;
   SDL_Rect area;
   Uint32 saved_flags;
   Uint8  saved_alpha;
-  
-  image = SDL_CreateRGBSurface(SDL_SWSURFACE,
-			       surface->w, surface->h,
-			       32,
+
+  putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                               surface->w, surface->h,
+                               32,
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
-			       0x000000FF,
-			       0x0000FF00,
-			       0x00FF0000,
-			       0xFF000000
+                               0x000000FF,
+                               0x0000FF00,
+                               0x00FF0000,
+                               0xFF000000
 #else
-			       0xFF000000,
-			       0x00FF0000,
-			       0x0000FF00,
-			       0x000000FF
+                               0xFF000000,
+                               0x00FF0000,
+                               0x0000FF00,
+                               0x000000FF
 #endif
-			       );
-  if ( image == NULL )
-    return NULL;
-  
+                               );
+  if ( putSurface == NULL )
+  {
+    this->setSurface(NULL);
+    return false;
+  }
+
   /* Save the alpha blending attributes */
   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
@@ -160,5 +163,5 @@
     SDL_SetAlpha(surface, 0, 0);
   }
-  
+
   /* Copy the surface into the GL texture image */
   area.x = 0;
@@ -166,13 +169,24 @@
   area.w = surface->w;
   area.h = surface->h;
-  SDL_BlitSurface(surface, &area, image, &area);
-  
+  SDL_BlitSurface(surface, &area, putSurface, &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;
+  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
+  {
+    SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
+    this->bAlpha = true;
+  }
+
+  return (this->setSurface(putSurface));
+}
+
+bool Texture::setSurface(SDL_Surface* newSurface)
+{
+  if (this->image != NULL)
+    SDL_FreeSurface(this->image);
+
+  this->image = newSurface;
+
+  return (this->image != NULL);
 }
 
@@ -183,30 +197,36 @@
  * @returns The ID of the texture.
  */
-GLuint Texture::loadTexToGL (SDL_Surface* surface) const
-{
-  GLuint texture = 0;
+GLuint Texture::loadTexToGL ()
+{
+  if (this->texture != 0 && glIsTexture(this->texture))
+    glDeleteTextures(1, &this->texture);
+  this->texture = 0;
+
+  if (this->image == NULL)
+    return 0;
+
   /* Create an OpenGL texture for the image */
-  glGenTextures(1, &texture);
-  glBindTexture(GL_TEXTURE_2D, texture);
+  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,
-	       surface->w, surface->h,
-	       0,
-	       GL_RGBA,
-	       GL_UNSIGNED_BYTE,
-	       surface->pixels);
+               0,
+               GL_RGBA,
+               this->image->w, this->image->h,
+               0,
+               GL_RGBA,
+               GL_UNSIGNED_BYTE,
+               this->image->pixels);
   // build the MipMaps
   gluBuild2DMipmaps(GL_TEXTURE_2D,
-		    GL_RGBA,
-		    surface->w,
-		    surface->h,
-		    GL_RGBA,
-		    GL_UNSIGNED_BYTE,
-		    surface->pixels);
+                    GL_RGBA,
+                    this->image->w,
+                    this->image->h,
+                    GL_RGBA,
+                    GL_UNSIGNED_BYTE,
+                    this->image->pixels);
   glBindTexture(GL_TEXTURE_2D, 0);
-  return texture;
-}
+  return this->texture;
+}
Index: trunk/src/lib/graphics/importer/texture.h
===================================================================
--- trunk/src/lib/graphics/importer/texture.h	(revision 5755)
+++ trunk/src/lib/graphics/importer/texture.h	(revision 5768)
@@ -1,48 +1,48 @@
 /*!
-  \file texture.h
-  \brief Contains the texture class, that handles the reading of Images into Texutre-files.
-
-  @todo procedural textures
-*/
+ * @file texture.h
+ * @brief Contains the texture class, that handles the reading of Images into Texutre-files.
+ */
 
 #ifndef _TEXTURE_H
 #define _TEXTURE_H
 
-#include "glincl.h"
 #include "base_object.h"
 
-#include "debug.h"
+#include "glincl.h"
 
+/* Forward Declaration */
 struct SDL_Surface;
 
 //! an enumerator for different procedural texture-types
 typedef enum TEXTURE_TYPE { TEXTURE_RADIAL_ALIAS,
-                            TEXTURE_NOISE };
+  TEXTURE_NOISE };
 
 //! A Class, that reads in Textures from different fileformats.
-class Texture : public BaseObject
-{
- public:
-  Texture(const char* imageName = NULL);
+  class Texture : public BaseObject
+  {
+    public:
+      Texture(const char* imageName = NULL);
   //  Texture(TEXTURE_TYPE type, int resolution);
-  ~Texture();
+      ~Texture();
 
-  bool loadImage(const char* imageName);
-  bool rebuild();
+      bool loadImage(const char* imageName);
+      bool rebuild();
 
-  /** @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 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;}
 
- private:
-  SDL_Surface* prepareSurface(SDL_Surface* input);
-  GLuint loadTexToGL (SDL_Surface* surface) const;
+    protected:
+      bool prepareSurface(SDL_Surface* input);
+      bool setSurface(SDL_Surface* newSurface);
 
- private:
-  GLuint        texture;            //!< The Texture-ID of opengl from this Texture.
-  bool          bAlpha;             //!< if the texture has an alpha channel.
-  SDL_Surface*  image;   
-};
+      GLuint loadTexToGL ();
+
+    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.
+  };
 
 #endif /* _TEXTURE_H */
