Index: trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- trunk/src/lib/graphics/importer/texture.cc	(revision 6848)
+++ trunk/src/lib/graphics/importer/texture.cc	(revision 6859)
@@ -70,50 +70,50 @@
 {
   if (Texture::texturesEnabled)
+  {
+    if (this->image != NULL)
     {
-      if (this->image != NULL)
+      SDL_FreeSurface(this->image);
+      this->image = NULL;
+    }
+    if (this->texture != 0)
+    {
+      glDeleteTextures(1, &this->texture);
+      this->texture = 0;
+    }
+    if (imageName != NULL)
+    {
+      SDL_Surface* tmpSurf;
+      if (this->texture != 0 && glIsTexture(this->texture))
+        glDeleteTextures(1, &this->texture);
+      // load the new Image to memory
+      tmpSurf = IMG_Load(imageName);
+      if(tmpSurf != NULL)
+      {
+        PRINTF(4)("loading Image %s\n", imageName);
+        bool hasAlpha;
+        SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha);
+        if (newSurf != NULL)
         {
-          SDL_FreeSurface(this->image);
-          this->image = NULL;
+          this->setSurface(newSurf);
+          this->setAlpha(hasAlpha);
+          this->setTexture(Texture::loadTexToGL(newSurf, target));
         }
-      if (this->texture != 0)
-        {
-          glDeleteTextures(1, &this->texture);
-          this->texture = 0;
-        }
-      if (imageName != NULL)
-        {
-          SDL_Surface* tmpSurf;
-          if (this->texture != 0 && glIsTexture(this->texture))
-            glDeleteTextures(1, &this->texture);
-          // load the new Image to memory
-          tmpSurf = IMG_Load(imageName);
-          if(tmpSurf != NULL)
-          {
-            PRINTF(4)("loading Image %s\n", imageName);
-            bool hasAlpha;
-            SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha);
-            if (newSurf != NULL)
-            {
-              this->setSurface(newSurf);
-              this->setAlpha(hasAlpha);
-              this->setTexture(Texture::loadTexToGL(newSurf, target));
-            }
-
-            SDL_FreeSurface(tmpSurf);
-            return true;
-          }
-          else
-            {
-              PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
-              this->texture = 0;
-              return false;
-            }
-        }
+
+        SDL_FreeSurface(tmpSurf);
+        return true;
+      }
       else
-        {
-          PRINTF(2)("Image-Name not specified\n");
-          return false;
-        }
+      {
+        PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
+        this->texture = 0;
+        return false;
+      }
     }
+    else
+    {
+      PRINTF(2)("Image-Name not specified\n");
+      return false;
+    }
+  }
   return false;
 }
@@ -127,15 +127,15 @@
 {
   if (this->texture != 0)
-    {
-      if (glIsTexture(this->texture))
-        glDeleteTextures(1,&this->texture);
-      this->setTexture(0);
-    }
+  {
+    if (glIsTexture(this->texture))
+      glDeleteTextures(1,&this->texture);
+    this->setTexture(0);
+  }
 
   if (this->image != NULL)
-    {
-      PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
-      this->setTexture(loadTexToGL(this->image));
-    }
+  {
+    PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
+    this->setTexture(loadTexToGL(this->image));
+  }
 }
 
@@ -194,13 +194,13 @@
                                     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
                                    );
@@ -213,5 +213,6 @@
   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
   saved_alpha = surface->format->alpha;
-  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
+  {
     SDL_SetAlpha(surface, 0, 0);
   }
@@ -242,7 +243,7 @@
 GLuint Texture::loadTexToGL (const SDL_Surface* surface, GLenum target) const
 {
-//   if (this->texture != 0 && glIsTexture(this->texture))
-//     glDeleteTextures(1, &this->texture);
-//   this->texture = 0;
+  //   if (this->texture != 0 && glIsTexture(this->texture))
+  //     glDeleteTextures(1, &this->texture);
+  //   this->texture = 0;
 
   int      errorCode = 0;           //!< the error code for the texture loading functions
@@ -283,4 +284,5 @@
                GL_UNSIGNED_BYTE,
                surface->pixels);
+  printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target);
 
   // build the MipMaps automaticaly
@@ -296,8 +298,4 @@
     PRINTF(1)("Error while loading texture (mipmap generation), gluBuild2DMipmaps returned %i\n", errorCode);
 
-  // Deselect newly built texture, as we do not want to display with this texture.
-  if (target == GL_TEXTURE_2D)
-    glBindTexture(target, 0);
-
   return texture;
 }
