Index: /orxonox/branches/parenting/src/importer/material.cc
===================================================================
--- /orxonox/branches/parenting/src/importer/material.cc	(revision 3343)
+++ /orxonox/branches/parenting/src/importer/material.cc	(revision 3344)
@@ -50,6 +50,6 @@
   if (this->name)
     delete []this->name;
-  if (this->diffuseTextureSet)
-    glDeleteTextures (1, &this->diffuseTexture);
+  if (this->diffuseTexture)
+    this->diffuseTexture;
   if (this->nextMat)
     delete this->nextMat;
@@ -89,4 +89,8 @@
   this->setTransparency(0.0);
 
+
+  this->diffuseTexture = NULL;
+  this->ambientTexture = NULL;
+  this->specularTexture = NULL;
 
   this->diffuseTextureSet = false;
@@ -145,5 +149,5 @@
 
   if (this->diffuseTextureSet)
-    glBindTexture(GL_TEXTURE_2D, this->diffuseTexture);
+    glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
   else
     glBindTexture(GL_TEXTURE_2D, 0);
@@ -318,6 +322,6 @@
 {
   PRINTF(3)("setting Diffuse Map %s\n", dMap);
-  Texture* tmp = new Texture();
-  this->diffuseTextureSet = tmp->loadImage(dMap, &this->diffuseTexture);
+  diffuseTexture = new Texture();
+  this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
 
 }
Index: /orxonox/branches/parenting/src/importer/material.h
===================================================================
--- /orxonox/branches/parenting/src/importer/material.h	(revision 3343)
+++ /orxonox/branches/parenting/src/importer/material.h	(revision 3344)
@@ -70,7 +70,7 @@
   float transparency;//!< The transperency of the Material.
 
-  GLuint diffuseTexture; //!< The diffuse texture of the Material.
-  GLuint ambientTexture; //!< The ambient texture of the Material.
-  GLuint specularTexture;//!< The specular texture of the Material.
+  Texture* diffuseTexture; //!< The diffuse texture of the Material.
+  Texture* ambientTexture; //!< The ambient texture of the Material.
+  Texture* specularTexture;//!< The specular texture of the Material.
   
   bool diffuseTextureSet; //!< Chekcs if the diffuse texture is Set.
Index: /orxonox/branches/parenting/src/importer/texture.cc
===================================================================
--- /orxonox/branches/parenting/src/importer/texture.cc	(revision 3343)
+++ /orxonox/branches/parenting/src/importer/texture.cc	(revision 3344)
@@ -113,4 +113,37 @@
 }
 
+
+
+/**
+   \brief Constructor for a Texture
+*/
+Texture::Texture(void)
+{
+  this->pImage = new Image;
+  this->pImage->data = NULL;
+  this->texture = 0;
+}
+
+/**
+   \brief Destructor of a Texture
+   
+   Frees Data, and deletes the textures from GL
+*/
+Texture::~Texture(void)
+{
+  if (this->pImage->data)
+    delete []this->pImage->data;
+  delete pImage;
+  if (this->texture)
+    glDeleteTextures(1, &this->texture);
+}
+
+/**
+   \returns The Texture-identifier number.
+*/
+GLuint Texture::getTexture(void)
+{
+    return this->texture;
+}
 
 /**
@@ -147,4 +180,9 @@
 }
 
+/**
+   \brief a Simple function that switches two char values
+   \param a The first value
+   \param b The second value
+*/
 inline void Texture::swap (unsigned char &a, unsigned char &b)
 {
@@ -161,9 +199,9 @@
    \param texture The Texture to apply it to.
 */
-bool Texture::loadTexToGL (Image* pImage, GLuint* texture)
+bool Texture::loadTexToGL (Image* pImage)
 {
   PRINTF(2)("Loading texture to OpenGL-Environment.\n");
-  glGenTextures(1, texture);
-  glBindTexture(GL_TEXTURE_2D, *texture);
+  glGenTextures(1, &this->texture);
+  glBindTexture(GL_TEXTURE_2D, this->texture);
   /* not Working, and not needed. 
   glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
@@ -179,5 +217,5 @@
 
 #ifdef HAVE_SDL_SDL_IMAGE_H
-bool Texture::loadImage(char* imageName, GLuint* texture)
+bool Texture::loadImage(char* imageName)
 {
   char* imgNameWithPath = searchTextureInPaths(imageName);
@@ -185,5 +223,4 @@
     {
       SDL_Surface* map;
-      Image* pImage = new Image;
       map=IMG_Load(imgNameWithPath);
       if(!map)
@@ -209,5 +246,5 @@
 	    swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]);
  
-      this->loadTexToGL (pImage, texture);
+      this->loadTexToGL (this->pImage);
     }
   else
@@ -225,5 +262,5 @@
    2. ToDO: Checks where to find the Image
 */
-bool Texture::loadImage(char* imageName, GLuint* texture)
+bool Texture::loadImage(char* imageName)
 {
   char* imgNameWithPath = searchTextureInPaths(imageName);
@@ -233,5 +270,5 @@
 	{
 	  PRINTF(3)("Requested bmp-image. Trying to Import.\n");
-	  return this->loadBMP(imgNameWithPath, texture);
+	  return this->loadBMP(imgNameWithPath);
 	}
       
@@ -239,15 +276,15 @@
 	{
 	  PRINTF(3)("Requested jpeg-image. Trying to Import\n");
-	  return this->loadJPG(imgNameWithPath, texture);
+	  return this->loadJPG(imgNameWithPath);
 	}
       else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
 	{
 	  PRINTF(3)("Requested tga-image. Trying to Import\n");
-	  return this->loadTGA(imgNameWithPath, texture);
+	  return this->loadTGA(imgNameWithPath);
 	}
       else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
 	{
 	  PRINTF(3)("Requested png-image. Trying to Import\n");
-	  return this->loadPNG(imgNameWithPath, texture);
+	  return this->loadPNG(imgNameWithPath);
 	}
       else
@@ -269,7 +306,6 @@
    \param texture A pointer to the Texture which should be read to.
 */
-bool Texture::loadBMP (char* bmpName, GLuint* texture)
-{
-  Image* pImage = new Image;
+bool Texture::loadBMP (char* bmpName)
+{
   FILE *file;
   unsigned long size;                 // size of the image in bytes.
@@ -353,5 +389,5 @@
       pImage->data[i+2] = temp;
     }
-  this->loadTexToGL (pImage, texture);
+  this->loadTexToGL (pImage);
   
 
@@ -374,5 +410,5 @@
    \param texture a reference to the Texture to write the image to
 */
-bool Texture::loadJPG (char* jpgName, GLuint* texture)
+bool Texture::loadJPG (char* jpgName)
 {
 #ifdef HAVE_JPEGLIB_H
@@ -451,5 +487,5 @@
     exit(0);
   
-  this->loadTexToGL (pImage, texture);
+  this->loadTexToGL (pImage);
   if (pImage)
     {
@@ -474,5 +510,5 @@
    \param texture a reference to the Texture to write the image to
 */
-bool Texture::loadTGA(const char * tgaName, GLuint* texture)
+bool Texture::loadTGA(const char * tgaName)
 {
   typedef struct
@@ -505,5 +541,5 @@
   if(memcmp(uTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
     {
-      loadUncompressedTGA(tgaName, fTGA, texture);
+      loadUncompressedTGA(tgaName, fTGA);
       if (fTGA)
 	fclose (fTGA);
@@ -511,5 +547,5 @@
   else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
     {
-      loadCompressedTGA(tgaName, fTGA, texture);
+      loadCompressedTGA(tgaName, fTGA);
 	if (fTGA)
 	  fclose (fTGA);
@@ -531,5 +567,5 @@
    \param texture a reference to the Texture to write the image to
 */
-bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA, GLuint* texture)
+bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA)
 {
   GLubyte header[6];      // First 6 Useful Bytes From The Header 
@@ -542,5 +578,4 @@
   GLuint  Bpp;		  // Bits Per Pixel 
 
-  Image* pImage = new Image;
   GLuint cswap;
   if(fread(header, sizeof(header), 1, fTGA) == 0)
@@ -595,5 +630,5 @@
     }
   
-  this->loadTexToGL (pImage, texture);
+  this->loadTexToGL (pImage);
 
   return true;
@@ -606,5 +641,5 @@
    \param texture a reference to the Texture to write the image to
 */
-bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture)
+bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA)
 {
   GLubyte header[6];      // First 6 Useful Bytes From The Header 
@@ -617,7 +652,4 @@
   GLuint  Bpp;		  // Bits Per Pixel 
 
-  Image* pImage = new Image;
-
-  
   if(fread(header, sizeof(header), 1, fTGA) == 0)
     {
@@ -778,5 +810,5 @@
   while(currentpixel < pixelcount);	// Loop while there are still pixels left
 
-  this->loadTexToGL (pImage, texture);
+  this->loadTexToGL (pImage);
 
   return true;
@@ -796,8 +828,7 @@
    \param texture a reference to the Texture to write the image to
 */
-bool Texture::loadPNG(const char* pngName, GLuint* texture)
+bool Texture::loadPNG(const char* pngName)
 {
 #ifdef HAVE_PNG_H
-  Image* pImage = new Image;
 
   FILE *PNG_file = fopen(pngName, "rb");
@@ -912,5 +943,5 @@
     }
   */
-  this->loadTexToGL (pImage, texture);  
+  this->loadTexToGL (pImage);  
   
   free(pImage->data);
Index: /orxonox/branches/parenting/src/importer/texture.h
===================================================================
--- /orxonox/branches/parenting/src/importer/texture.h	(revision 3343)
+++ /orxonox/branches/parenting/src/importer/texture.h	(revision 3344)
@@ -64,22 +64,27 @@
     GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data.
   };
+  Image* pImage;
+  GLuint texture;
   char* searchTextureInPaths(char* texName) const;
   inline void swap(unsigned char &a, unsigned char &b);
  public:
+  Texture(void);
+  ~Texture(void);
 
-  bool loadTexToGL (Image* pImage, GLuint* texture);
+  GLuint getTexture(void);
+  bool loadTexToGL (Image* pImage);
 
-  bool loadImage(char* imageName, GLuint* texture);
+  bool loadImage(char* imageName);
 #ifndef HAVE_SDL_SDL_IMAGE_H
 
-  bool loadBMP (char* bmpName, GLuint* texture);
+  bool loadBMP (char* bmpName);
 
-  bool loadJPG (char* jpgName, GLuint* texture);
+  bool loadJPG (char* jpgName);
 
   /// TGA ///
 
-  bool loadTGA(const char * tgaName, GLuint* texture);
-  bool loadUncompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
-  bool loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
+  bool loadTGA(const char * tgaName);
+  bool loadUncompressedTGA(const char * filename, FILE * fTGA);
+  bool loadCompressedTGA(const char * filename, FILE * fTGA);
 
   bool loadPNG(const char* pngName, GLuint* texture);
