Index: trunk/src/lib/graphics/importer/texture.cc
===================================================================
--- trunk/src/lib/graphics/importer/texture.cc	(revision 7711)
+++ trunk/src/lib/graphics/importer/texture.cc	(revision 7727)
@@ -30,5 +30,5 @@
 
 /**
- *  Constructor for a Texture
+ * @brief Constructor for a Texture
 */
 Texture::Texture(const std::string& imageName, GLenum target)
@@ -50,8 +50,8 @@
 
 /**
- *  Destructor of a Texture
-
-   Frees Data, and deletes the textures from GL
-*/
+ * @brief Destructor of a Texture
+ *
+ * Frees Data, and deletes the textures from GL
+ */
 Texture::~Texture()
 {
@@ -64,5 +64,5 @@
 
 /**
- *  loads an Image from a file to a Texture
+ * @brief loads an Image from a file to a Texture
  * @param imageName The image to load
 */
@@ -121,5 +121,6 @@
 
 /**
- * rebuilds the texture.
+ * @brief rebuilds the texture.
+ *
  * reloads the Texture from Memory to OpenGL.
  */
@@ -142,5 +143,5 @@
 
 /**
- * set the surface this Texture handles
+ * @brief set the surface this Texture handles
  * @param newSurface the new Surface to set as the image for this Texture.
  *
@@ -162,5 +163,5 @@
 
 /**
- * enables, disables textures
+ * @brief enables, disables textures
  * @param texturesEnabled true if the textures should be enabled
  */
@@ -175,5 +176,5 @@
 //////////////////////////////////////
 /**
- * converts surface to a new SDL_Surface, that is loadable by openGL
+ * @brief converts surface to a new SDL_Surface, that is loadable by openGL
  * @param surface the Surface to convert
  * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false.
@@ -182,4 +183,5 @@
 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
 {
+  assert(surface != NULL);
   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
 
@@ -190,7 +192,19 @@
 
   hasAlpha = false;
-  retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
+  int pixelDepth = 24;
+
+  /* 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);
+    hasAlpha = true;
+    pixelDepth = 32;
+  }
+
+  retSurface = SDL_CreateRGBSurface(SDL_HWSURFACE,
                                     surface->w, surface->h,
-                                    32,
+                                    pixelDepth,
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
                                     0x000000FF,
@@ -206,15 +220,5 @@
                                    );
   if ( retSurface == NULL )
-  {
     return NULL;
-  }
-
-  /* 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 */
@@ -237,5 +241,5 @@
 
 /**
- *  Loads a Texture to the openGL-environment.
+ * @brief Loads a Texture to the openGL-environment.
  * @param surface the Image to load to openGL
  * @returns The ID of the texture.
@@ -246,4 +250,5 @@
   //     glDeleteTextures(1, &this->texture);
   //   this->texture = 0;
+  assert(surface != NULL);
 
   int      errorCode = 0;           //!< the error code for the texture loading functions
@@ -252,8 +257,14 @@
   int      mipmapWidth = 0;         //!< the width of the mipmap
   int      mipmapHight = 0;         //!< the height of the mipmap
-
-
-  if (surface == NULL)
-    return 0;
+  GLenum   format = GL_RGB;
+  if (this->bAlpha)
+  {
+    format = GL_RGBA;
+    assert(surface->format->BitsPerPixel == 32);
+  }
+  else
+  {
+    assert(surface->format->BitsPerPixel == 24);
+  }
 
   /* Create an OpenGL texture for the image */
@@ -261,4 +272,9 @@
   glBindTexture(target, texture);
 
+//   glTexImage2D(target,  0,  format,
+//                surface->w,  surface->h,
+//                0, format,  GL_UNSIGNED_BYTE,
+//                surface->pixels);
+
   glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
@@ -275,22 +291,11 @@
 
   /* build the Texture  OpenGL V >= 1.1 */
-  glTexImage2D(target,
-               0,
-               GL_RGBA,
-               surface->w,
-               surface->h,
-               0,
-               GL_RGBA,
-               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
-  errorCode = gluBuild2DMipmaps(target,
-                                GL_RGBA,
-                                surface->w,
-                                surface->h,
-                                GL_RGBA,
-                                GL_UNSIGNED_BYTE,
+  errorCode = gluBuild2DMipmaps(target, format,
+                                surface->w,  surface->h,
+                                format,  GL_UNSIGNED_BYTE,
                                 surface->pixels
                                );
Index: trunk/src/lib/graphics/importer/texture.h
===================================================================
--- trunk/src/lib/graphics/importer/texture.h	(revision 7711)
+++ trunk/src/lib/graphics/importer/texture.h	(revision 7727)
@@ -43,9 +43,7 @@
 
     protected:
-
       bool setSurface(SDL_Surface* newSurface);
       bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
       bool setTexture(GLuint texture) { this->texture = texture; };
-
 
     private:
