Index: orxonox/branches/images/importer/material.cc
===================================================================
--- orxonox/branches/images/importer/material.cc	(revision 3095)
+++ orxonox/branches/images/importer/material.cc	(revision 3096)
@@ -633,5 +633,5 @@
     }
   
-  if(fread(&tgaHeader, sizeof(TGAHeader), 1, fTGA) == 0) /// hmm... don't know if this is io
+  if(fread(&tgaHeader, sizeof(TGAHeader), 1, fTGA) == 0)
     {
       printf("Error could not read file header of %s\n", tgaName);
@@ -651,5 +651,5 @@
   else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
     {
-      //loadCompressedTGA(tgaName, fTGA, texture);
+      loadCompressedTGA(tgaName, fTGA, texture);
 	if (fTGA)
 	  fclose (fTGA);
@@ -735,191 +735,169 @@
 }
 
-#ifdef __auskomentiert__
-bool Material::LoadCompressedTGA(Texture * texture,const char * filename, FILE * fTGA)
-{
-  GLuint pixelcount	= Height * Width;							/* Nuber of pixels in the image */
-  GLuint currentpixel	= 0;												/* Current pixel being read */
-  GLuint currentbyte	= 0;												/* Current byte */
-  GLubyte * colorbuffer = (GLubyte *)malloc(bytesPerPixel);			/* Storage for 1 pixel */
-  
-  if(fread(header, sizeof(header), 1, fTGA) == 0)				/* Attempt to read header */
-    {
-      printf("Error could not read info header");							/* Display Error */
-      if(fTGA != NULL)													/* If file is open */
+bool Material::loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture)
+{
+  GLubyte header[6];      // First 6 Useful Bytes From The Header 
+  GLuint  bytesPerPixel;  // Holds Number Of Bytes Per Pixel Used In The TGA File 
+  GLuint  imageSize;	  // Used To Store The Image Size When Setting Aside Ram 
+  GLuint  temp;		  // Temporary Variable
+  GLuint  type;
+  GLuint  Height;	  // Height of Image 
+  GLuint  Width;	  // Width of Image 
+  GLuint  Bpp;		  // Bits Per Pixel 
+
+  Image* pImage = new Image;
+
+  
+  if(fread(header, sizeof(header), 1, fTGA) == 0)
+    {
+      printf("Error could not read info header\n");
+      return false;
+    }
+  
+  Width = pImage->width  = header[1] * 256 + header[0];
+  Height = pImage->height = header[3] * 256 + header[2];
+  Bpp = pImage->bpp	= header[4];
+
+  GLuint pixelcount	= Height * Width;
+  GLuint currentpixel	= 0;
+  GLuint currentbyte	= 0;
+  GLubyte * colorbuffer = (GLubyte *)malloc(bytesPerPixel);
+
+  //Make sure all pImage info is ok 
+  if((pImage->width <= 0) || (pImage->height <= 0) || ((pImage->bpp != 24) && (pImage->bpp !=32)))
+    {
+      printf("Error Invalid pImage information\n");
+      return false;
+    }
+  
+  bytesPerPixel	= (Bpp / 8);
+  imageSize		= (bytesPerPixel * Width * Height);
+  pImage->data	= (GLubyte*) malloc(imageSize);
+  
+  if(pImage->data == NULL)
+    {
+      printf("Error could not allocate memory for image\n");
+      return false;
+    }
+  
+  do
+    {
+      GLubyte chunkheader = 0;
+      
+      if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
 	{
-	  fclose(fTGA);													/* Close it */
+	  printf("Error could not read RLE header\n");
+	  if(pImage->data != NULL)
+	    {
+	      free(pImage->data);
+	    }
+	  return false;
 	}
-      return false;														/* Return failed */
-    }
-  
-  pImage->width  = header[1] * 256 + header[0];					/* Determine The TGA Width	(highbyte*256+lowbyte) */
-  pImage->height = header[3] * 256 + header[2];					/* Determine The TGA Height	(highbyte*256+lowbyte) */
-  pImage->bpp	= header[4];										/* Determine Bits Per Pixel */
-  Width		= pImage->width;										/* Copy width to local structure */
-  Height		= pImage->height;										/* Copy width to local structure */
-  Bpp			= pImage->bpp;											/* Copy width to local structure */
-  
-  if((pImage->width <= 0) || (pImage->height <= 0) || ((pImage->bpp != 24) && (pImage->bpp !=32)))	/*Make sure all pImage info is ok */
-    {
-      printf("Error Invalid pImage information");						/* If it isnt...Display error */
-      if(fTGA != NULL)													/* Check if file is open */
+      // If the ehader is < 128, it means the that is the number of RAW color packets minus 1 
+      if(chunkheader < 128)
 	{
-	  fclose(fTGA);													/* Ifit is, close it */
-	}
-      return false;														/* Return failed */
-    }
-  
-  bytesPerPixel	= (Bpp / 8);									/* Compute BYTES per pixel */
-  imageSize		= (bytesPerPixel * Width * Height);		/* Compute amout of memory needed to store image */
-  pImage->data	= (GLubyte *)malloc(imageSize);					/* Allocate that much memory */
-  
-  if(pImage->data == NULL)											/* If it wasnt allocated correctly.. */
-    {
-      printf("Error could not allocate memory for image");				/* Display Error */
-      fclose(fTGA);														/* Close file */
-      return false;														/* Return failed */
-    }
-  
-  do
-    {
-      GLubyte chunkheader = 0;											/* Storage for "chunk" header */
-      
-      if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)				/* Read in the 1 byte header */
-	{
-	  printf("Error could not read RLE header");						/*Display Error */
-	  if(fTGA != NULL)												/* If file is open */
-	    {
-	      fclose(fTGA);												/* Close file */
-	    }
-	  if(pImage->data != NULL)									/* If there is stored image data */
-	    {
-	      free(pImage->data);									/* Delete image data */
-	    }
-	  return false;													/* Return failed */
-	}
-      
-      if(chunkheader < 128)												/* If the ehader is < 128, it means the that is the number of RAW color packets minus 1 */
-	{
-	  short counter;													/* that follow the header */
-	  chunkheader++;													/* add 1 to get number of following color values */
-	  for(counter = 0; counter < chunkheader; counter++)				/* Read RAW color values */
-	    {
-	      if(fread(colorbuffer, 1, bytesPerPixel, fTGA) != bytesPerPixel) /* Try to read 1 pixel */
+	  short counter;
+	  chunkheader++;
+	  // Read RAW color values
+	  for(counter = 0; counter < chunkheader; counter++)
+	    { 
+	      // Try to read 1 pixel 
+	      if(fread(colorbuffer, 1, bytesPerPixel, fTGA) != bytesPerPixel)
 		{
-		  printf("Error could not read image data");				/* IF we cant, display an error */
-		  
-		  if(fTGA != NULL)										/* See if file is open */
+		  printf("Error could not read image data\n");
+		  if(colorbuffer != NULL)
 		    {
-		      fclose(fTGA);										/* If so, close file */
+		      free(colorbuffer);
 		    }
 		  
-		  if(colorbuffer != NULL)									/* See if colorbuffer has data in it */
+		  if(pImage->data != NULL)
 		    {
-		      free(colorbuffer);									/* If so, delete it */
+		      free(pImage->data);
 		    }
 		  
-		  if(pImage->data != NULL)										/* See if there is stored Image data */
+		  return false;	
+		}
+	      // write to memory 
+	      // Flip R and B vcolor values around in the process 
+	      pImage->data[currentbyte	  ] = colorbuffer[2];				    
+	      pImage->data[currentbyte + 1] = colorbuffer[1];
+	      pImage->data[currentbyte + 2] = colorbuffer[0];
+	      
+	      if(bytesPerPixel == 4) // if its a 32 bpp image 
+		{
+		  pImage->data[currentbyte + 3] = colorbuffer[3];// copy the 4th byte 
+		}
+	      
+	      currentbyte += bytesPerPixel;
+	      currentpixel++;
+
+	      // Make sure we haven't read too many pixels 
+	      if(currentpixel > pixelcount)	
+		{
+		  printf("Error too many pixels read\n");
+		  if(colorbuffer != NULL)
 		    {
-		      free(pImage->data);										/* If so, delete it too */
+		      free(colorbuffer);
 		    }
 		  
-		  return false;														/* Return failed */
-		}
-	      /* write to memory */
-	      pImage->data[currentbyte		] = colorbuffer[2];				    /* Flip R and B vcolor values around in the process */
-	      pImage->data[currentbyte + 1	] = colorbuffer[1];
-	      pImage->data[currentbyte + 2	] = colorbuffer[0];
-	      
-	      if(bytesPerPixel == 4)												/* if its a 32 bpp image */
-		{
-		  pImage->data[currentbyte + 3] = colorbuffer[3];				/* copy the 4th byte */
-		}
-	      
-	      currentbyte += bytesPerPixel;										/* Increase thecurrent byte by the number of bytes per pixel */
-	      currentpixel++;															/* Increase current pixel by 1 */
-	      
-	      if(currentpixel > pixelcount)											/* Make sure we havent read too many pixels */
-		{
-		  printf("Error too many pixels read");								/* if there is too many... Display an error! */
-		  
-		  if(fTGA != NULL)													/* If there is a file open */
+		  if(pImage->data != NULL)
 		    {
-		      fclose(fTGA);													/* Close file */
+		      free(pImage->data);
 		    }
 		  
-		  if(colorbuffer != NULL)												/* If there is data in colorbuffer */
-		    {
-		      free(colorbuffer);												/* Delete it */
-		    }
-		  
-		  if(pImage->data != NULL)										/* If there is Image data */
-		    {
-		      free(pImage->data);										/* delete it */
-		    }
-		  
-		  return false;														/* Return failed */
+		  return false;
 		}
 	    }
 	}
-      else																			/* chunkheader > 128 RLE data, next color  reapeated chunkheader - 127 times */
+      // chunkheader > 128 RLE data, next color  reapeated chunkheader - 127 times
+      else
 	{
 	  short counter;
-	  chunkheader -= 127;															/* Subteact 127 to get rid of the ID bit */
-	  if(fread(colorbuffer, 1, bytesPerPixel, fTGA) != bytesPerPixel)		/* Attempt to read following color values */
+	  chunkheader -= 127;	// Subteact 127 to get rid of the ID bit 
+	  if(fread(colorbuffer, 1, bytesPerPixel, fTGA) != bytesPerPixel) // Attempt to read following color values 
 	    {
-	      printf("Error could not read from file");			/* If attempt fails.. Display error (again) */
-	      
-	      if(fTGA != NULL)														/* If thereis a file open */
+	      printf("Error could not read from file");
+	      if(colorbuffer != NULL)
 		{
-		  fclose(fTGA);														/* Close it */
+		  free(colorbuffer);
 		}
 	      
-	      if(colorbuffer != NULL)													/* If there is data in the colorbuffer */
+	      if(pImage->data != NULL)
 		{
-		  free(colorbuffer);													/* delete it */
+		  free(pImage->data);
 		}
 	      
-	      if(pImage->data != NULL)											/* If thereis image data */
+	      return false;
+	    }
+	  
+	  for(counter = 0; counter < chunkheader; counter++) //copy the color into the image data as many times as dictated
+	    {							
+	      // switch R and B bytes areound while copying 												/* by the header */
+	      pImage->data[currentbyte	  ] = colorbuffer[2];
+	      pImage->data[currentbyte + 1] = colorbuffer[1];
+	      pImage->data[currentbyte + 2] = colorbuffer[0];
+	      
+	      if(bytesPerPixel == 4)
 		{
-		  free(pImage->data);											/* delete it */
+		  pImage->data[currentbyte + 3] = colorbuffer[3];
 		}
 	      
-	      return false;															/* return failed */
-	    }
-	  
-	  for(counter = 0; counter < chunkheader; counter++)					/* copy the color into the image data as many times as dictated */
-	    {																			/* by the header */
-	      pImage->data[currentbyte		] = colorbuffer[2];					/* switch R and B bytes areound while copying */
-	      pImage->data[currentbyte + 1	] = colorbuffer[1];
-	      pImage->data[currentbyte + 2	] = colorbuffer[0];
+	      currentbyte += bytesPerPixel;
+	      currentpixel++;
 	      
-	      if(bytesPerPixel == 4)												/* If TGA images is 32 bpp */
+	      if(currentpixel > pixelcount)
 		{
-		  pImage->data[currentbyte + 3] = colorbuffer[3];				/* Copy 4th byte */
-		}
-	      
-	      currentbyte += bytesPerPixel;										/* Increase current byte by the number of bytes per pixel */
-	      currentpixel++;															/* Increase pixel count by 1 */
-	      
-	      if(currentpixel > pixelcount)											/* Make sure we havent written too many pixels */
-		{
-		  printf("Error too many pixels read");								/* if there is too many... Display an error! */
-		  
-		  if(fTGA != NULL)													/* If there is a file open */
+		  printf("Error too many pixels read\n");
+		  if(colorbuffer != NULL)
 		    {
-		      fclose(fTGA);													/* Close file */
+		      free(colorbuffer);
 		    }
 		  
-		  if(colorbuffer != NULL)												/* If there is data in colorbuffer */
+		  if(pImage->data != NULL)
 		    {
-		      free(colorbuffer);												/* Delete it */
+		      free(pImage->data);
 		    }
 		  
-		  if(pImage->data != NULL)										/* If there is Image data */
-		    {
-		      free(pImage->data);										/* delete it */
-		    }
-		  
-		  return false;														/* Return failed */
+		  return false;
 		}
 	    }
@@ -927,8 +905,8 @@
     }
   
-  while(currentpixel < pixelcount);													/* Loop while there are still pixels left */
-  fclose(fTGA);																		/* Close the file */
-  return true;																		/* return success */
-}
-
-#endif
+  while(currentpixel < pixelcount);	/* Loop while there are still pixels left */
+  loadTexToGL (pImage, texture);
+
+  return true;
+}
+
Index: orxonox/branches/images/importer/material.h
===================================================================
--- orxonox/branches/images/importer/material.h	(revision 3095)
+++ orxonox/branches/images/importer/material.h	(revision 3096)
@@ -100,5 +100,5 @@
   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 loadCompressedTGA(const char * filename, FILE * fTGA, GLuint* texture);
 
 };
