Index: orxonox/trunk/src/importer/Makefile.am
===================================================================
--- orxonox/trunk/src/importer/Makefile.am	(revision 3237)
+++ orxonox/trunk/src/importer/Makefile.am	(revision 3365)
@@ -8,14 +8,16 @@
 importer_SOURCES= framework.cc \
 	          windowHandler.cc \
-	  	  object.cc \
+	  	  model.cc \
 	  	  array.cc \
 	  	  material.cc \
+		  texture.cc \
 	  	  vector.cc 
 
 noinst_HEADERS= framework.h \
 	  	windowHandler.h \
-	  	object.h \
+	  	model.h \
 	  	array.h \
-		material.h 
+		material.h \
+		texture.h
 
 
Index: orxonox/trunk/src/importer/Makefile.in
===================================================================
--- orxonox/trunk/src/importer/Makefile.in	(revision 3237)
+++ orxonox/trunk/src/importer/Makefile.in	(revision 3365)
@@ -54,6 +54,6 @@
 PROGRAMS = $(bin_PROGRAMS)
 am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \
-	object.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \
-	vector.$(OBJEXT)
+	model.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \
+	texture.$(OBJEXT) vector.$(OBJEXT)
 importer_OBJECTS = $(am_importer_OBJECTS)
 importer_LDADD = $(LDADD)
@@ -62,6 +62,7 @@
 am__depfiles_maybe = depfiles
 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/framework.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/material.Po ./$(DEPDIR)/object.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po
+@AMDEP_TRUE@	./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/windowHandler.Po
 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@@ -176,14 +177,16 @@
 importer_SOURCES = framework.cc \
 	          windowHandler.cc \
-	  	  object.cc \
+	  	  model.cc \
 	  	  array.cc \
 	  	  material.cc \
+		  texture.cc \
 	  	  vector.cc 
 
 noinst_HEADERS = framework.h \
 	  	windowHandler.h \
-	  	object.h \
+	  	model.h \
 	  	array.h \
-		material.h 
+		material.h \
+		texture.h
 
 all: all-am
@@ -256,5 +259,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/framework.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/object.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/windowHandler.Po@am__quote@
Index: orxonox/trunk/src/importer/framework.cc
===================================================================
--- orxonox/trunk/src/importer/framework.cc	(revision 3237)
+++ orxonox/trunk/src/importer/framework.cc	(revision 3365)
@@ -52,5 +52,5 @@
 int main(int argc, char *argv[])
 {
-  int verbose = 3;
+  verbose = 2;
 
   PRINTF(2)("This is The big verbose-Test %i, %s\n", 1, "cool");
@@ -71,9 +71,9 @@
   PRINTF(2)("screensize: %i, %i\n", wHandler.screen->w, wHandler.screen->h);
   if (argc>=3)
-    obj = new Object (argv[1], atof(argv[2]));
+    obj = new Model (argv[1], atof(argv[2]));
   else if (argc>=2)
-    obj = new Object(argv[1]);
+    obj = new Model(argv[1]);
   else 
-    obj = new Object();
+    obj = new Model();
   
   M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0); 
@@ -215,5 +215,5 @@
 	  case SDLK_c:
 	    if (!obj)
-	      obj = new Object(argv[1]);
+	      obj = new Model(argv[1]);
 	    break;
 	  }
Index: orxonox/trunk/src/importer/framework.h
===================================================================
--- orxonox/trunk/src/importer/framework.h	(revision 3237)
+++ orxonox/trunk/src/importer/framework.h	(revision 3365)
@@ -3,5 +3,5 @@
  
 #include "windowHandler.h" // Include the Whandler Basecode
-#include "object.h"
+#include "model.h"
 #include "vector.h"
 
@@ -33,5 +33,5 @@
 
 WindowHandler wHandler;  // Create an instance of the whandler basecode class
-Object* obj;
+Model* obj;
 
 
Index: orxonox/trunk/src/importer/material.cc
===================================================================
--- orxonox/trunk/src/importer/material.cc	(revision 3237)
+++ orxonox/trunk/src/importer/material.cc	(revision 3365)
@@ -13,93 +13,10 @@
    co-programmer: ...
 
-   TGA-code: borrowed from nehe-Tutorials
-
 */
 
 #include "material.h"
 
-// headers only for PathList
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <fstream>
-
 using namespace std;
 
-/**
-   \brief creates a ned PathList.
-   
-   It is a good idea to use this as an initial List,
-   because if you give on a name the Path will not be checked for its existence.
-*/
-PathList::PathList()
-{
-  this->pathName = NULL;
-  this->next = NULL;
-}
-
-/**
-   \brief Creates a new PathList with a Name.
-   \param pName the Name of The Path.
-
-   This function just adds the Path without checking if it exists.
-*/
-PathList::PathList(char* pName)
-{
-  this->pathName = new char [strlen(pName)+1];
-  strcpy (this->pathName, pName);
-  this->next = NULL;
-}
-
-/**
-   \brief destroys a PathList
-
-   It does this by deleting the Name and then delete its preceding PathList.
-*/
-PathList::~PathList()
-{
-  if (this->pathName)
-    delete []this->pathName;
-  if (this->next)
-    delete this->next;
-}
-
-/**
-   \brief Adds a new Pathlist Element.
-   \param pName
-   
-   Adding a Path automatically checks if the Path exists,
-   and if it does not it will not add it to the List.
-*/
-void PathList::addPath (char* pName)
-{
-  if (pName[0] == '\0')
-    {
-      PRINTF(3)("not Adding empty Path to the List.\n");
-      return;
-    }
-  char* tmpPName = new char[strlen(pName)];
-  strncpy(tmpPName, pName, strlen(pName)-1);
-  tmpPName[strlen(pName)-1] = '\0';
-  if (access (tmpPName, F_OK) == 0)
-    {
-      struct stat status;
-      stat(tmpPName, &status);
-      if (status.st_mode & S_IFDIR)
-	{
-	  PRINTF(2)("Adding Path %s to the PathList.\n", pName);
-	  PathList* tmpPathList = this;
-	  while (tmpPathList->next)
-	    tmpPathList = tmpPathList->next;
-	  tmpPathList->next = new PathList(pName);
-	}
-      else
-	PRINTF(2)("You tried to add non-folder %s to a PathList.\n", tmpPName);
-    }
-  else
-      PRINTF(2)("You tried to add non-existing folder %s to a PathList.\n", tmpPName);
-  delete []tmpPName;
-}
 
 /**
@@ -133,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;
@@ -172,7 +89,8 @@
   this->setTransparency(0.0);
 
-  if (!this->pathList)
-    this->pathList = new PathList("");
-
+
+  this->diffuseTexture = NULL;
+  this->ambientTexture = NULL;
+  this->specularTexture = NULL;
 
   this->diffuseTextureSet = false;
@@ -182,6 +100,4 @@
   
 }
-
-PathList *Material::pathList = NULL;
 
 /**
@@ -233,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);
@@ -394,40 +310,6 @@
 void Material::addTexturePath(char* pathName)
 {
-  this->pathList->addPath (pathName);
-}
-
-/**
-   \brief Searches for a Texture inside one of the defined Paths
-   \param texName The name of the texture o search for.
-   \returns pathName+texName if texName was found in the pathList. NULL if the Texture is not found.
-*/
-char* Material::searchTextureInPaths(char* texName) const
-{
-  char* tmpName = NULL;
-  PathList* pList = pathList;
-  while (pList)
-    {
-      if (pList->pathName)
-	{
-	  tmpName = new char [strlen(pList->pathName)+strlen(texName)+1];
-	  strcpy(tmpName, pList->pathName);
-	}
-      else
-	{
-	  tmpName = new char [strlen(texName)+1];
-	  tmpName[0]='\0';
-	}
-      strcat(tmpName, texName);
-      if (access (tmpName, F_OK) == 0)
-	return tmpName;
-      
-      if (tmpName)
-	delete []tmpName;
-      tmpName = NULL;
-      pList = pList->next;
-    }
-  return NULL;
-}
-
+  PathList::getInstance()->addPath(pathName);
+}
 
 // MAPPING //
@@ -440,7 +322,6 @@
 {
   PRINTF(3)("setting Diffuse Map %s\n", dMap);
-
-  //  diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
-  this->diffuseTextureSet = this->loadImage(dMap, &this->diffuseTexture);
+  diffuseTexture = new Texture();
+  this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
 
 }
@@ -477,765 +358,2 @@
 
 }
-
-/**
-   \brief Loads a Texture to the openGL-environment.
-   \param pImage The Image to load to openGL
-   \param texture The Texture to apply it to.
-*/
-bool Material::loadTexToGL (Image* pImage, GLuint* texture)
-{
-  PRINTF(2)("Loading texture to OpenGL-Environment.\n");
-  glGenTextures(1, texture);
-  glBindTexture(GL_TEXTURE_2D, *texture);
-  /* not Working, and not needed. 
-  glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
-		height, 0, GL_BGR,
-		GL_UNSIGNED_BYTE, map->pixels );
-  */ 
-  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->width, pImage->height, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
-  
-  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
-  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);	
-}
-
-
-#ifdef HAVE_SDL_SDL_IMAGE_H
-bool Material::loadImage(char* imageName, GLuint* texture)
-{
-  char* imgNameWithPath = searchTextureInPaths(imageName);
-  if (imgNameWithPath)
-    {
-      SDL_Surface* map;
-      Image* pImage = new Image;
-      map=IMG_Load(imgNameWithPath);
-      if(!map)
-	{
-	  PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
-	  return false;
-	}
-      pImage->height = map->h;
-      pImage->width  = map->w;
-      pImage->data   = (GLubyte*)map->pixels;
-      if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))
-	for (int i=0;i<map->h * map->w *3;i+=3)
-	  { 
-	    GLuint temp = pImage->data[i];
-	    pImage->data[i] = pImage->data[i+2];
-	    pImage->data[i+2] = temp;
-	  }
-      this->loadTexToGL (pImage, texture);
-    }
-  else
-    {
-      PRINTF(1)("Image not Found: %s\n", imgNameWithPath);
-      return false;
-    }
-}
-
-
-#else /* HAVE_SDL_SDL_IMAGE_H */
-/**
-   \brief Makes the Programm ready to Read-in a texture-File
-   1. Checks what type of Image should be imported
-   2. ToDO: Checks where to find the Image
-*/
-bool Material::loadImage(char* imageName, GLuint* texture)
-{
-  char* imgNameWithPath = searchTextureInPaths(imageName);
-  if (imgNameWithPath)
-    {
-      if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".bmp", 4))
-	{
-	  PRINTF(3)("Requested bmp-image. Trying to Import.\n");
-	  return this->loadBMP(imgNameWithPath, texture);
-	}
-      
-      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".jpg", 4) || !strncmp(imgNameWithPath+strlen(imgNameWithPath)-5, ".jpg", 5))
-	{
-	  PRINTF(3)("Requested jpeg-image. Trying to Import\n");
-	  return this->loadJPG(imgNameWithPath, texture);
-	}
-      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
-	{
-	  PRINTF(3)("Requested tga-image. Trying to Import\n");
-	  return this->loadTGA(imgNameWithPath, texture);
-	}
-      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
-	{
-	  PRINTF(3)("Requested png-image. Trying to Import\n");
-	  return this->loadPNG(imgNameWithPath, texture);
-	}
-      else
-	{
-	  PRINTF(1)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", imgNameWithPath);
-	  return false;
-	}
-    }
-  else
-    {
-      PRINTF(1)("Image not Found: %s\n", imgNameWithPath);
-      return false;
-    }
-}
-
-/**
-   \brief reads in a Windows BMP-file, and imports it to openGL.
-   \param bmpName The name of the Image to load.
-   \param texture A pointer to the Texture which should be read to.
-*/
-bool Material::loadBMP (char* bmpName, GLuint* texture)
-{
-  Image* pImage = new Image;
-  FILE *file;
-  unsigned long size;                 // size of the image in bytes.
-  unsigned long i;                    // standard counter.
-  unsigned short int planes;          // number of planes in image (must be 1) 
-  unsigned short int bpp;             // number of bits per pixel (must be 24)
-  GLuint temp;                          // temporary color storage for bgr-rgb conversion.
-
-  // make sure the file is there.
-  if ((file = fopen(bmpName, "rb"))==NULL)
-    {
-      PRINTF(1)("File Not Found : %s\n",bmpName);
-      return false;
-    }
-  // seek through the bmp header, up to the width/height:
-  fseek(file, 18, SEEK_CUR);
-  
-  // read the width
-  if ((i = fread(&pImage->width, 4, 1, file)) != 1) 
-    {
-      PRINTF(1)("Error reading width from %s.\n", bmpName);
-      return false;
-    }
-  // read the height 
-  if ((i = fread(&pImage->height, 4, 1, file)) != 1) 
-    {
-      PRINTF(1)("Error reading height from %s.\n", bmpName);
-      return false;
-    }
-  
-  // calculate the size (assuming 24 bits or 3 bytes per pixel).
-  size = pImage->width * pImage->height * 3;
-  
-  // read the planes
-  if ((fread(&planes, 2, 1, file)) != 1) 
-    {
-      PRINTF(1)("Error reading planes from %s.\n", bmpName);
-      return false;
-    }
-  if (planes != 1) 
-    {
-      PRINTF(1)("Planes from %s is not 1: %u\n", bmpName, planes);
-      return false;
-    }
-  
-  // read the bpp
-  if ((i = fread(&bpp, 2, 1, file)) != 1) 
-    {
-      PRINTF(1)("Error reading bpp from %s.\n", bmpName);
-      return false;
-    }
-  if (bpp != 24) 
-    {
-      PRINTF(1)("Bpp from %s is not 24: %u\n", bmpName, bpp);
-      return false;
-    }
-  
-  // seek past the rest of the bitmap header.
-  fseek(file, 24, SEEK_CUR);
-  
-  // read the data. 
-  pImage->data = (GLubyte *) malloc(size);
-  if (pImage->data == NULL) 
-    {
-      PRINTF(1)("Error allocating memory for color-corrected image data");
-      return false;	
-    }
-  
-  if ((i = fread(pImage->data, size, 1, file)) != 1) 
-    {
-      PRINTF(1)("Error reading image data from %s.\n", bmpName);
-      return false;
-    }
-  fclose(file);
-
-  // reverse all of the colors. (bgr -> rgb)
-  for (i=0;i<size;i+=3) 
-    { 
-      temp = pImage->data[i];
-      pImage->data[i] = pImage->data[i+2];
-      pImage->data[i+2] = temp;
-    }
-  this->loadTexToGL (pImage, texture);
-  
-
-  if (pImage)
-    {
-      if (pImage->data)
-	{
-	  free(pImage->data);
-	}
-      
-      free(pImage);
-    }
-  return true;
-
-}
-
-/**
-   \brief reads in a jpg-file
-   \param jpgName the Name of the Image to load
-   \param texture a reference to the Texture to write the image to
-*/
-bool Material::loadJPG (char* jpgName, GLuint* texture)
-{
-#ifdef HAVE_JPEGLIB_H
-  struct jpeg_decompress_struct cinfo;
-  Image *pImage = NULL;
-  FILE *pFile;
-  
-  // Open a file pointer to the jpeg file and check if it was found and opened 
-  if((pFile = fopen(jpgName, "rb")) == NULL) 
-    {
-      // Display an error message saying the file was not found, then return NULL
-      PRINTF(1)("Unable to load JPG File %s.\n", jpgName);
-      return false;
-    }
-  
-  // Create an error handler
-  jpeg_error_mgr jerr;
-  
-  // Have our compression info object point to the error handler address
-  cinfo.err = jpeg_std_error(&jerr);
-  
-  // Initialize the decompression object
-  jpeg_create_decompress(&cinfo);
-  
-  // Specify the data source (Our file pointer)	
-  jpeg_stdio_src(&cinfo, pFile);
-  
-  // Allocate the structure that will hold our eventual jpeg data (must free it!)
-  pImage = (Image*)malloc(sizeof(Image));
-  
-  // DECOFING
-  // Read in the header of the jpeg file
-  jpeg_read_header(&cinfo, TRUE);
-  
-  // Start to decompress the jpeg file with our compression info
-  jpeg_start_decompress(&cinfo);
-  
-  // Get the image dimensions and row span to read in the pixel data
-  pImage->rowSpan = cinfo.image_width * cinfo.num_components;
-  pImage->width   = cinfo.image_width;
-  pImage->height   = cinfo.image_height;
-  
-  // Allocate memory for the pixel buffer
-  pImage->data = new unsigned char[pImage->rowSpan * pImage->height];
-  
-  // Here we use the library's state variable cinfo.output_scanline as the
-  // loop counter, so that we don't have to keep track ourselves.
-  
-  // Create an array of row pointers
-  unsigned char** rowPtr = new unsigned char*[pImage->height];
-  for (int i = 0; i < pImage->height; i++)
-    rowPtr[i] = &(pImage->data[i*pImage->rowSpan]);
-  
-  // Now comes the juice of our work, here we extract all the pixel data
-  int rowsRead = 0;
-  while (cinfo.output_scanline < cinfo.output_height) 
-    {
-      // Read in the current row of pixels and increase the rowsRead count
-      rowsRead += jpeg_read_scanlines(&cinfo, &rowPtr[rowsRead], cinfo.output_height - rowsRead);
-    }
-  
-  // Delete the temporary row pointers
-  delete [] rowPtr;
-  
-  // Finish decompressing the data
-  jpeg_finish_decompress(&cinfo);//  decodeJPG(&cinfo, pImage);
-  
-  // This releases all the stored memory for reading and decoding the jpeg
-  jpeg_destroy_decompress(&cinfo);
-  
-  // Close the file pointer that opened the file
-  fclose(pFile);
-  
-
-  if(pImage == NULL)
-    exit(0);
-  
-  this->loadTexToGL (pImage, texture);
-  if (pImage)
-    {
-      if (pImage->data)
-	{
-	  free(pImage->data);
-	}
-      
-      free(pImage);
-    }
-  return true;
-#else /* HAVE_JPEGLIB_H */
-  PRINTF(1)("sorry, but you did not compile with jpeg-support.\nEither install SDL_image or jpeglib, and recompile to see the image\n");
-  return false;
-#endif /* HAVE_JPEGLIB_H */
-
-}
-
-/**
-   \brief reads in a tga-file
-   \param tgaName the Name of the Image to load
-   \param texture a reference to the Texture to write the image to
-*/
-bool Material::loadTGA(const char * tgaName, GLuint* texture)
-{
-  typedef struct
-  {
-    GLubyte Header[12];
-  } TGAHeader;
-  TGAHeader tgaHeader;			
-  
-  GLubyte uTGAcompare[12] = {0,0,2, 0,0,0,0,0,0,0,0,0};	// Uncompressed TGA Header 
-  GLubyte cTGAcompare[12] = {0,0,10,0,0,0,0,0,0,0,0,0};	// Compressed TGA Header 
-  FILE * fTGA;
-  fTGA = fopen(tgaName, "rb");
-
-  if(fTGA == NULL)
-    {
-      PRINTF(1)("Error could not open texture file: %s\n", tgaName);
-      return false;
-    }
-  
-  if(fread(&tgaHeader, sizeof(TGAHeader), 1, fTGA) == 0)
-    {
-      PRINTF(1)("Error could not read file header of %s\n", tgaName);
-      if(fTGA != NULL)
-	{
-	  fclose(fTGA);
-	}
-      return false;
-    }
-  
-  if(memcmp(uTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
-    {
-      loadUncompressedTGA(tgaName, fTGA, texture);
-      if (fTGA)
-	fclose (fTGA);
-    }
-  else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
-    {
-      loadCompressedTGA(tgaName, fTGA, texture);
-	if (fTGA)
-	  fclose (fTGA);
-    }
-  else
-    {
-      PRINTF(1)("Error TGA file be type 2 or type 10\n");
-      if (fTGA)
-	fclose(fTGA);
-      return false;
-    }
-  return true;
-}
-
-/**
-   \brief reads in an uncompressed tga-file
-   \param filename the Name of the Image to load
-   \param fTGA a Pointer to a File, that should be read
-   \param texture a reference to the Texture to write the image to
-*/
-bool Material::loadUncompressedTGA(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;
-  GLuint cswap;
-  if(fread(header, sizeof(header), 1, fTGA) == 0)
-    {
-      PRINTF(1)("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];
-  // Make sure all information is valid
-  if((pImage->width <= 0) || (pImage->height <= 0) || ((pImage->bpp != 24) && (pImage->bpp !=32)))
-    {
-      PRINTF(1)("Error invalid texture information\n");
-      return false;
-    }
-  
-  if(pImage->bpp == 24)	
-    {
-      pImage->type = GL_RGB;
-    }
-  else
-    {
-      pImage->type = GL_RGBA;
-    }
-  
-  bytesPerPixel	= (Bpp / 8);
-  imageSize = (bytesPerPixel * Width * Height);
-  pImage->data = (GLubyte*) malloc(imageSize);
-  
-  if(pImage->data == NULL)
-    {
-      PRINTF(1)("Error could not allocate memory for image\n");
-      return false;
-    }
-  
-  if(fread(pImage->data, 1, imageSize, fTGA) != imageSize)
-    {
-      PRINTF(1)("Error could not read image data\n");
-      if(pImage->data != NULL)
-	{
-	  free(pImage->data);
-	}
-      return false;
-    }
-  
-  for(cswap = 0; cswap < (int)imageSize; cswap += bytesPerPixel)
-    {
-      pImage->data[cswap] ^= pImage->data[cswap+2] ^=
-	pImage->data[cswap] ^= pImage->data[cswap+2];
-    }
-  
-  this->loadTexToGL (pImage, texture);
-
-  return true;
-}
-
-/**
-   \brief reads in a compressed tga-file
-   \param filename the Name of the Image to load
-   \param fTGA a Pointer to a File, that should be read
-   \param texture a reference to the Texture to write the image to
-*/
-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(1)("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(1)("Error Invalid pImage information\n");
-      return false;
-    }
-  
-  bytesPerPixel	= (Bpp / 8);
-  imageSize		= (bytesPerPixel * Width * Height);
-  pImage->data	= (GLubyte*) malloc(imageSize);
-  
-  if(pImage->data == NULL)
-    {
-      PRINTF(1)("Error could not allocate memory for image\n");
-      return false;
-    }
-  
-  do
-    {
-      GLubyte chunkheader = 0;
-      
-      if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
-	{
-	  PRINTF(1)("Error could not read RLE header\n");
-	  if(pImage->data != NULL)
-	    {
-	      free(pImage->data);
-	    }
-	  return false;
-	}
-      // If the ehader is < 128, it means the that is the number of RAW color packets minus 1 
-      if(chunkheader < 128)
-	{
-	  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(1)("Error could not read image data\n");
-		  if(colorbuffer != NULL)
-		    {
-		      free(colorbuffer);
-		    }
-		  
-		  if(pImage->data != NULL)
-		    {
-		      free(pImage->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(1)("Error too many pixels read\n");
-		  if(colorbuffer != NULL)
-		    {
-		      free(colorbuffer);
-		    }
-		  
-		  if(pImage->data != NULL)
-		    {
-		      free(pImage->data);
-		    }
-		  
-		  return false;
-		}
-	    }
-	}
-      // 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 
-	    {
-	      PRINTF(1)("Error could not read from file");
-	      if(colorbuffer != NULL)
-		{
-		  free(colorbuffer);
-		}
-	      
-	      if(pImage->data != NULL)
-		{
-		  free(pImage->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
-	      pImage->data[currentbyte	  ] = colorbuffer[2];
-	      pImage->data[currentbyte + 1] = colorbuffer[1];
-	      pImage->data[currentbyte + 2] = colorbuffer[0];
-	      
-	      if(bytesPerPixel == 4)
-		{
-		  pImage->data[currentbyte + 3] = colorbuffer[3];
-		}
-	      
-	      currentbyte += bytesPerPixel;
-	      currentpixel++;
-	      
-	      if(currentpixel > pixelcount)
-		{
-		  PRINTF(1)("Error too many pixels read\n");
-		  if(colorbuffer != NULL)
-		    {
-		      free(colorbuffer);
-		    }
-		  
-		  if(pImage->data != NULL)
-		    {
-		      free(pImage->data);
-		    }
-		  
-		  return false;
-		}
-	    }
-	}
-    }
-  
-  while(currentpixel < pixelcount);	// Loop while there are still pixels left
-
-  this->loadTexToGL (pImage, texture);
-
-  return true;
-}
-
-
-/*
-static int ST_is_power_of_two(unsigned int number)
-{
-  return (number & (number - 1)) == 0;
-}
-*/
-
-/**
-   \brief reads in a png-file
-   \param pngName the Name of the Image to load
-   \param texture a reference to the Texture to write the image to
-*/
-bool Material::loadPNG(const char* pngName, GLuint* texture)
-{
-#ifdef HAVE_PNG_H
-  Image* pImage = new Image;
-
-  FILE *PNG_file = fopen(pngName, "rb");
-  if (PNG_file == NULL)
-    {
-      return 0;
-    }
-  
-  GLubyte PNG_header[8];
-  
-  fread(PNG_header, 1, 8, PNG_file);
-  if (png_sig_cmp(PNG_header, 0, 8) != 0)
-    {
-      PRINTF(2)("Not Recognized as a pngFile\n");
-      fclose (PNG_file);
-      return 0;
-    }
-  
-  png_structp PNG_reader = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-  if (PNG_reader == NULL)
-    {
-      fclose(PNG_file);
-      return 0;
-    }
-  
-  png_infop PNG_info = png_create_info_struct(PNG_reader);
-  if (PNG_info == NULL)
-    {
-      png_destroy_read_struct(&PNG_reader, NULL, NULL);
-      fclose(PNG_file);
-      return 0;
-    }
-  
-  png_infop PNG_end_info = png_create_info_struct(PNG_reader);
-  if (PNG_end_info == NULL)
-    {
-      png_destroy_read_struct(&PNG_reader, &PNG_info, NULL);
-      fclose(PNG_file);
-      return 0;
-    }
-  
-  if (setjmp(png_jmpbuf(PNG_reader)))
-    {
-      png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
-      fclose(PNG_file);
-      return (0);
-    }
-  
-  png_init_io(PNG_reader, PNG_file);
-  png_set_sig_bytes(PNG_reader, 8);
-  
-  png_read_info(PNG_reader, PNG_info);
-  
-  pImage->width = png_get_image_width(PNG_reader, PNG_info);
-  pImage->height = png_get_image_height(PNG_reader, PNG_info);
-  
-  png_uint_32 bit_depth, color_type;
-  bit_depth = png_get_bit_depth(PNG_reader, PNG_info);
-  color_type = png_get_color_type(PNG_reader, PNG_info);
-  
-  if (color_type == PNG_COLOR_TYPE_PALETTE)
-    {
-      png_set_palette_to_rgb(PNG_reader);
-    }
-  
-  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
-    {
-      png_set_gray_1_2_4_to_8(PNG_reader);
-    }
-  
-  if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
-    {
-      png_set_gray_to_rgb(PNG_reader);
-    }
-  
-  if (png_get_valid(PNG_reader, PNG_info, PNG_INFO_tRNS))
-    {
-      png_set_tRNS_to_alpha(PNG_reader);
-    }
-  else
-    {
-      png_set_filler(PNG_reader, 0xff, PNG_FILLER_AFTER);
-    }
-  
-  if (bit_depth == 16)
-    {
-      png_set_strip_16(PNG_reader);
-    }
-  
-  png_read_update_info(PNG_reader, PNG_info);
-  
-  pImage->data = (png_byte*)malloc(4 * pImage->width * pImage->height);
-  png_byte** PNG_rows = (png_byte**)malloc(pImage->height * sizeof(png_byte*));
-  
-  unsigned int row;
-  for (row = 0; row < pImage->height; ++row)
-    {
-      PNG_rows[pImage->height - 1 - row] = pImage->data + (row * 4 * pImage->width);
-    }
-  
-  png_read_image(PNG_reader, PNG_rows);
-  
-  free(PNG_rows);
-  
-  png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
-  fclose(PNG_file);
-  
-  /*  if (!ST_is_power_of_two(pImage->width) || !ST_is_power_of_two(pImage->height))
-    {
-      free(pImage->data);
-      return 0;
-    }
-  */
-  this->loadTexToGL (pImage, texture);  
-  
-  free(pImage->data);
-  
-  return true;
-#else /* HAVE_PNG_H */
-  PRINTF(1)("sorry, but you did not compile with png-support.\nEither install SDL_image or libpng, and recompile to see the image\n");
-  return false;
-#endif /* HAVE_PNG_H */
-
-}
-
-#endif /* HAVE_SDL_SDL_IMAGE_H */
Index: orxonox/trunk/src/importer/material.h
===================================================================
--- orxonox/trunk/src/importer/material.h	(revision 3237)
+++ orxonox/trunk/src/importer/material.h	(revision 3365)
@@ -14,4 +14,5 @@
 
 #include "../stdincl.h"
+#include "texture.h"
 
 #if HAVE_CONFIG_H 
@@ -19,36 +20,5 @@
 #endif /* HAVE_CONFIG_H */
 
-#ifdef HAVE_SDL_SDL_IMAGE_H
-#include <SDL/SDL_image.h>
-#else
-// IMAGE LIBS //
-#ifdef HAVE_JPEGLIB_H
-extern "C"{         // This has to be done, because not a c++ lib
-#include <jpeglib.h>
-}
-#endif /* HAVE_JPEGLIB_H */
-#ifdef HAVE_PNG_H
-#include <png.h>
-#endif /* HAVE_PNG_H */
-#endif /* HAVE_SDL_SDL_IMAGE_H */
 
-//! Class to handle lists of paths.
-/**
-   \todo Ability to return Paths by itself.
-
-   It is simple to use, and good, for all PathList you want.
-   just create a new Pathlist, and add Paths.
-*/
-class PathList
-{
- public:
-  PathList();
-  PathList(char* pName);
-
-  ~PathList();
-  void addPath (char* pName);
-  char* pathName;          //!< The Name of the current Path.
-  PathList* next;          //!< Pointer to the next Pathlist.
-};
 
 
@@ -92,16 +62,4 @@
 
  private:
-  //! Struct to handle Infos about an Image
-  struct Image
-  {
-    int rowSpan;    //!< The count of the rows this Image has.
-    GLuint width;   //!< The width of the Image.
-    GLuint height;  //!< The height of the Image.
-    GLuint bpp;     //!< BitsPerPixel
-    GLuint type;    //!< Type of the Image.
-    GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data.
-  };
-
-
   char* name;        //!< The Name of the Material.
   int illumModel;    //!< The IlluminationModel is either flat or smooth.
@@ -112,9 +70,7 @@
   float transparency;//!< The transperency of the Material.
 
-  static PathList* pathList; //!< A pointer to the first element of Pathlist. This is static, because pathlists are global \todo copy this to the Globals.h or DataTank for deletion at the end.
-  
-  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.
@@ -124,22 +80,5 @@
   Material* nextMat; //!< pointer to the Next Material of the List. NULL if no next exists.
 
-  // TEXTURING
-  bool loadTexToGL (Image* pImage, GLuint* texture);
 
-  bool loadImage(char* imageName, GLuint* texture);
-#ifndef HAVE_SDL_SDL_IMAGE_H
-
-  bool loadBMP (char* bmpName, GLuint* texture);
-
-  bool loadJPG (char* jpgName, GLuint* texture);
-
-  /// 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 loadPNG(const char* pngName, GLuint* texture);
-#endif
 };
 #endif
Index: orxonox/trunk/src/importer/model.cc
===================================================================
--- orxonox/trunk/src/importer/model.cc	(revision 3365)
+++ orxonox/trunk/src/importer/model.cc	(revision 3365)
@@ -0,0 +1,976 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+*/
+
+#include "model.h"
+int verbose = 1; //! \todo should be GLOBAL
+using namespace std;
+
+/**
+   \brief Creates a 3D-Model, but does not load any 3D-models.
+
+   This Constructor is pretty useless, because why load no model in an model-loader??
+*/
+Model::Model ()
+{
+
+  this->initialize();
+
+  this->BoxModel();
+
+  this->importToGL ();
+
+  this->cleanup();
+}
+
+/**
+   \brief Crates a 3D-Model and loads in a File.
+   \param fileName file to parse and load (must be a .obj file)
+*/
+Model::Model(char* fileName)
+{
+  this->initialize();
+
+  this->importFile (fileName);
+
+  this->importToGL ();
+
+  this->cleanup();
+}
+
+/**
+   \brief Crates a 3D-Model, loads in a File and scales it.
+   \param fileName file to parse and load (must be a .obj file)
+   \param scaling The factor that the model will be scaled with.
+*/
+Model::Model(char* fileName, float scaling)
+{
+  this->initialize();
+  this->scaleFactor = scaling;
+
+  this->importFile (fileName);
+
+  this->importToGL ();
+
+  this->cleanup();
+}
+
+/**
+   \brief deletes an Model.
+
+   Looks if any from model allocated space is still in use, and if so deleted it.
+*/
+Model::~Model()
+{
+  PRINTF(2)("Deleting display Lists.\n");
+  Group* walker = this->firstGroup;
+  while (walker != NULL)
+    {
+      glDeleteLists (walker->listNumber, 1);
+      Group* delWalker = walker;
+      walker = walker->next;
+      delete delWalker;
+    }
+
+  if (this->objPath)
+    delete []this->objPath;
+  if (this->objFileName)
+    delete []this->objFileName;
+  if (this->mtlFileName)
+    delete []this->mtlFileName;
+  PRINTF(2)("Deleting Materials.\n");
+  if (this->material)
+    delete this->material;
+}
+
+
+/**
+   \brief Draws the Models of all Groups.
+   It does this by just calling the Lists that must have been created earlier.
+*/
+void Model::draw (void) const
+{
+  PRINTF(2)("drawing the 3D-Models\n"); 
+  Group* walker = this->firstGroup;
+  while (walker != NULL)
+    {
+      PRINTF(3)("Drawing model %s\n", walker->name);
+      glCallList (walker->listNumber);
+      walker = walker->next;
+    }
+}
+
+/**
+   \brief Draws the Model number groupNumber
+   \param groupNumber The number of the group that will be displayed.
+
+   It does this by just calling the List that must have been created earlier.
+*/
+void Model::draw (int groupNumber) const 
+{
+  if (groupNumber >= this->groupCount)
+    {
+      PRINTF(1)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
+      return;
+    }
+  PRINTF(2)("drawing the requested 3D-Models if found.\n"); 
+  Group* walker = this->firstGroup;
+  int counter = 0;
+  while (walker != NULL)
+    {
+      if (counter == groupNumber)
+	{
+	  PRINTF(2)("Drawing model number %i named %s\n", counter, walker->name);
+	  glCallList (walker->listNumber);
+	  return;
+	}
+      ++counter;
+      walker = walker->next;
+    }
+  PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->objFileName);
+  return;
+
+}
+
+/**
+   \brief Draws the Model with a specific groupName
+   \param groupName The name of the group that will be displayed.
+
+   It does this by just calling the List that must have been created earlier.
+*/
+void Model::draw (char* groupName) const
+{
+  PRINTF(2)("drawing the requested 3D-Models if found.\n"); 
+  Group* walker = this->firstGroup;
+  while (walker != NULL)
+    {
+      if (!strcmp(walker->name, groupName))
+	{
+	  PRINTF(2)("Drawing model %s\n", walker->name);
+	  glCallList (walker->listNumber);
+	  return;
+	}
+      walker = walker->next;
+    }
+  PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->objFileName);
+  return;
+}
+
+/**
+   \returns Count of the Models in this File
+*/
+int Model::getGroupCount (void) const
+{
+  return this->groupCount;
+}
+
+/**
+    \brief initializes the Model.
+
+    This Function initializes all the needed arrays, Lists and clientStates.
+    It also defines default values.
+*/
+bool Model::initialize (void)
+{
+  PRINTF(2)("new 3D-Model is being created\n"); 
+
+  // setting the start group;
+  this->firstGroup = new Group;
+  this->currentGroup = this->firstGroup;
+  this->groupCount = 0;
+  
+  this->initGroup (this->currentGroup);
+  this->objPath = NULL;
+  this->objFileName = NULL;
+  this->mtlFileName = NULL;
+  this->scaleFactor = 1;
+  this->material = new Material();
+
+  this->vertices = new Array();
+  this->vTexture = new Array();
+  this->normals = new Array();
+
+  return true;
+}
+
+/**
+   \brief initializes a new Group model
+   \param group the group that should be initialized.
+   \todo Maybe Group should be a Class, because it does a lot of stuff
+   
+*/
+bool Model::initGroup(Group* group)
+{
+  PRINTF(3)("Adding new Group\n");
+  group->name = "";
+  group->faceMode = -1;
+  group->faceCount = 0;  
+  group->next = NULL;
+
+  group->firstFace = new Face;
+  this->initFace (group->firstFace);
+  group->currentFace = group->firstFace;
+}
+
+/**
+   \brief initializes a new Face. (sets default Values)
+   \param face The face to initialize
+*/
+bool Model::initFace (Face* face)
+{
+  face->vertexCount = 0;
+
+  face->firstElem = NULL;
+  
+  face->materialString = NULL;
+  
+  face->next = NULL;
+
+  return true;
+}
+
+/**
+   \brief finalizes an Model.
+   This funcion is needed, to delete all the Lists, and arrays that are no more needed because they are already imported into openGL. This will be applied at the end of the importing Process.
+*/
+bool Model::cleanup(void)
+{
+  PRINTF(3)("cleaning up the 3D-Model to save Memory.\n");
+
+  if (this->vertices)
+    delete this->vertices;
+  if (this->vTexture)
+    delete this->vTexture;
+  if (this->normals)
+    delete this->normals;
+
+  this->cleanupGroup(this->firstGroup);
+  return true; 
+}
+
+/**
+   \brief Cleans up all groups starting from group.
+   \param group the first Group to clean
+*/
+bool Model::cleanupGroup (Group* group)
+{
+  PRINTF(3)("Cleaning up group\n");
+  if (group->firstFace != NULL)
+    {
+      cleanupFace (group->firstFace);
+      delete group->firstFace;
+    }
+
+  if (group->next !=NULL)
+    cleanupGroup (group->next);
+  return true;
+}
+
+/**
+   \brief Cleans up all Faces starting from face until NULL is reached.
+   \param face the first face to clean.
+*/
+bool Model::cleanupFace (Face* face)
+{
+  PRINTF(3)("Cleaning up Face\n");
+
+  if (face->materialString != NULL)
+      delete []face->materialString;
+  if (face->firstElem != NULL)
+    {
+      this->cleanupFaceElement(face->firstElem);
+      delete face->firstElem;
+    }
+      
+  if (face->next != NULL)
+    {
+      this->cleanupFace (face->next);
+      delete face->next;
+    }
+      
+}
+
+
+/**
+   \brief Cleans up all FaceElements starting from faceElem.
+   \param faceElem the first FaceElement to clean.
+*/
+bool Model::cleanupFaceElement(FaceElement* faceElem)
+{
+  if (faceElem->next != NULL)
+    {
+      this->cleanupFaceElement (faceElem->next);
+      delete faceElem->next;
+    }
+}
+
+/**
+   \brief Imports a obj file and handles the the relative location
+   \param fileName The file to import
+*/
+bool Model::importFile (char* fileName)
+{
+  PRINTF(3)("preparing to read in file: %s\n", fileName);
+
+
+#ifdef __WIN32__
+  // win32 path reading
+  char pathSplitter= '\\';
+#else /* __WIN32__ */
+  // unix path reading
+  char pathSplitter='/';
+#endif /* __WIN32__ */
+  char* tmpName = fileName;
+  if (tmpName[0] == pathSplitter)
+    tmpName++;
+  char* name = tmpName;
+  while (( tmpName = strchr (tmpName+1, pathSplitter)))
+    {
+      name = tmpName+1;
+    }
+  this->objPath = new char[name-fileName];
+  strncpy(this->objPath, fileName, name-fileName);
+  this->objPath[name-fileName] = '\0';
+  if (verbose >=2)
+    if (strlen(objPath)> 0)
+      PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath);
+    else
+      PRINTF(0)("Resolved file %s.\n", name);
+  
+  if (this->material)
+    this->material->addTexturePath(this->objPath);
+  this->objFileName = new char[strlen(name)+1];
+  strcpy (this->objFileName, name);
+  this->readFromObjFile ();
+  return true;
+}
+
+/**
+   \brief Reads in the .obj File and sets all the Values.
+   This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
+*/
+bool Model::readFromObjFile (void)
+{
+  char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
+  if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
+    return false;
+  strcpy(fileName, this->objPath);
+  strcat(fileName, this->objFileName);
+
+  ifstream* OBJ_FILE = new ifstream(fileName);
+  if (OBJ_FILE->fail())
+    {
+      PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Model instead.\n", fileName);
+      BoxModel();
+      OBJ_FILE->close();
+      delete []fileName;
+      delete OBJ_FILE;
+      return false;
+    }
+  PRINTF(2)("Reading from opened file %s\n", fileName);
+  char Buffer[10000];
+  while(!OBJ_FILE->eof())
+    {
+      OBJ_FILE->getline(Buffer, 10000);
+      PRINTF(3)("Read input line: %s\n", Buffer);
+      
+
+      // case vertice
+      if (!strncmp(Buffer, "v ", 2))
+	{
+	  this->readVertex(Buffer+2);
+	}
+
+      // case face
+      else if (!strncmp(Buffer, "f ", 2))
+	{
+	  this->readFace (Buffer+2);
+	}
+      
+      else if (!strncmp(Buffer, "mtllib ", 7))
+	{
+	  this->readMtlLib (Buffer+7);
+	}
+
+      else if (!strncmp(Buffer, "usemtl ", 7))
+	{
+	  this->readUseMtl (Buffer+7);
+	}
+
+      // case VertexNormal
+      else if (!strncmp(Buffer, "vn ", 3))
+	{
+	  this->readVertexNormal(Buffer+3);
+	}
+      
+      // case VertexTextureCoordinate
+      else if (!strncmp(Buffer, "vt ", 3))
+	{
+	  this->readVertexTexture(Buffer+3);
+	}
+      // case group
+      else if (!strncmp(Buffer, "g ", 2))
+	{
+	  this->readGroup (Buffer+2);
+	}
+      else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented
+	{
+	  if (verbose >= 2)
+	    PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer);
+	}
+    }
+  OBJ_FILE->close();
+  delete OBJ_FILE;
+  delete []fileName;
+  return true;
+
+}
+
+/**
+   \brief parses a group String
+   \param groupString the new Group to create
+
+   This function initializes a new Group. 
+   With it you should be able to import .obj-files with more than one Models inside. 
+*/
+bool Model::readGroup (char* groupString)
+{
+  PRINTF(3)("Read Group: %s.\n", groupString);
+  if (this->groupCount != 0 && this->currentGroup->faceCount>0)
+    {
+      //      finalizeGroup(currentGroup);
+      this->currentGroup = this->currentGroup->next = new Group;
+      this->initGroup(this->currentGroup);
+    }
+  // setting the group name if not default.
+  if (strcmp(groupString, "default"))
+    {
+      this->currentGroup->name = new char [strlen(groupString)+1];
+      strcpy(this->currentGroup->name, groupString);
+    }
+  ++this->groupCount;
+
+}
+
+/**
+   \brief parses a vertex-String
+   \param vertexString The String that will be parsed.
+
+   If a vertex line is found this function will inject it into the vertex-Array
+*/
+bool Model::readVertex (char* vertexString)
+{
+  float subbuffer1;
+  float subbuffer2;
+  float subbuffer3;
+  sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
+  PRINTF(3)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
+  this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
+  return true;
+}
+
+/**
+   \brief parses a face-string
+   \param faceString The String that will be parsed.
+
+   If a face line is found this function will add it to the glList.
+   The function makes a difference between QUADS and TRIANGLES, and will if changed re-open, set and re-close the gl-processe.
+*/
+bool Model::readFace (char* faceString)
+{
+  if (this->currentGroup->faceCount >0)
+    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
+  this->initFace (this->currentGroup->currentFace);
+
+  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
+  tmpElem->next = NULL;
+  while(strcmp (faceString, "\0"))
+    {
+      if (this->currentGroup->currentFace->vertexCount>0)
+	  tmpElem = tmpElem->next = new FaceElement;
+      tmpElem->next = NULL;
+
+      char tmpValue [50];
+      int tmpLen;
+      char* vertex = NULL;
+      char* texture = NULL;
+      char* normal = NULL;
+
+      sscanf (faceString, "%s", tmpValue);
+      tmpLen = strlen(tmpValue);
+      vertex = tmpValue;
+
+      if ((texture = strstr (vertex, "/")) != NULL)
+	{
+	  texture[0] = '\0';
+	  texture ++;
+	  
+	  if ((normal = strstr (texture, "/")) !=NULL)
+	    {
+	      normal[0] = '\0';
+	      normal ++;
+	    }	  
+	}
+      if (vertex)
+	tmpElem->vertexNumber = atoi(vertex)-1;
+      else
+	tmpElem->vertexNumber = -1;
+      if (texture)
+	tmpElem->texCoordNumber = atoi(texture)-1;
+      else
+	tmpElem->texCoordNumber = -1;
+      if (normal)
+	tmpElem->normalNumber = atoi(normal)-1;
+      else
+	tmpElem->normalNumber = -1;
+
+      faceString += tmpLen;
+      if (strcmp (faceString, "\0"))
+	faceString++;
+      this->currentGroup->currentFace->vertexCount++;
+    }
+
+  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
+}
+
+/**
+   \brief parses a vertexNormal-String
+   \param normalString The String that will be parsed.
+
+   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
+*/
+bool Model::readVertexNormal (char* normalString)
+{
+  float subbuffer1;
+  float subbuffer2;
+  float subbuffer3;
+  sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
+  PRINTF(3)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
+  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
+  return true;
+}
+
+/**
+   \brief parses a vertexTextureCoordinate-String
+   \param vTextureString The String that will be parsed.
+
+   If a vertexTextureCoordinate line is found,
+   this function will inject it into the vertexTexture-Array
+*/
+bool Model::readVertexTexture (char* vTextureString)
+{
+  float subbuffer1;
+  float subbuffer2;
+  sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
+  PRINTF(3)("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2);
+  this->vTexture->addEntry(subbuffer1);
+  this->vTexture->addEntry(subbuffer2);
+  return true;
+}
+
+/** 
+    \brief Function to read in a mtl File.
+    \param mtlFile The .mtl file to read
+
+    This Function parses all Lines of an mtl File.
+    The reason for it not to be in the materials-class is,
+    that a material does not have to be able to read itself in from a File.
+
+*/
+bool Model::readMtlLib (char* mtlFile)
+{
+  this->mtlFileName = new char [strlen(mtlFile)+1];
+  strcpy(this->mtlFileName, mtlFile);
+  char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
+  strcpy(fileName, this->objPath);
+  strcat(fileName, this->mtlFileName);
+  
+
+  PRINTF(3)("Opening mtlFile: %s\n", fileName);
+
+  ifstream* MTL_FILE = new ifstream (fileName);
+  if (MTL_FILE->fail())
+    {
+      PRINTF(1)("unable to open file: %s\n", fileName);
+      MTL_FILE->close();
+      delete []fileName;
+      delete MTL_FILE;
+      return false;
+    }
+  char Buffer[500];
+  Material* tmpMat = material;
+  while(!MTL_FILE->eof())
+    {
+      MTL_FILE->getline(Buffer, 500);
+      PRINTF(4)("found line in mtlFile: %s\n", Buffer);
+      
+
+      // create new Material
+      if (!strncmp(Buffer, "newmtl ", 7))
+	{
+	  tmpMat = tmpMat->addMaterial(Buffer+7);
+	  //	  PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat);
+	}
+      // setting a illumMode
+      else if (!strncmp(Buffer, "illum ", 6))
+	{
+	  tmpMat->setIllum(Buffer+6);
+
+	}
+      // setting Diffuse Color
+      else if (!strncmp(Buffer, "Kd ", 3))
+	{
+	  tmpMat->setDiffuse(Buffer+3);
+	}
+      // setting Ambient Color
+      else if (!strncmp(Buffer, "Ka ", 3))
+	{
+	  tmpMat->setAmbient(Buffer+3);
+	}
+      // setting Specular Color
+      else if (!strncmp(Buffer, "Ks ", 3))
+	{
+	  tmpMat->setSpecular(Buffer+3);
+	}
+      // setting The Specular Shininess
+      else if (!strncmp(Buffer, "Ns ", 3))
+	{
+	  tmpMat->setShininess(Buffer+3);
+	}
+      // setting up transparency
+      else if (!strncmp(Buffer, "d ", 2))
+	{
+	  tmpMat->setTransparency(Buffer+2);
+	}
+      else if (!strncmp(Buffer, "Tf ", 3))
+	{
+	  tmpMat->setTransparency(Buffer+3);
+	}
+      
+      else if (!strncmp(Buffer, "map_Kd ", 7))
+	{
+	  tmpMat->setDiffuseMap(Buffer+7);
+	}
+      else if (!strncmp(Buffer, "map_Ka ", 7))
+	{
+	  tmpMat->setAmbientMap(Buffer+7);
+	}
+      else if (!strncmp(Buffer, "map_Ks ", 7))
+	{
+	  tmpMat->setSpecularMap(Buffer+7);
+	}
+      else if (!strncmp(Buffer, "bump ", 5))
+	{
+	  tmpMat->setBump(Buffer+7);
+	}
+     
+
+    }
+  MTL_FILE->close();
+  delete []fileName;
+  delete MTL_FILE;
+  return true;
+}
+
+/**
+   \brief Function that selects a material, if changed in the obj file.
+   \param matString the Material that will be set.
+*/
+bool Model::readUseMtl (char* matString)
+{
+  if (!this->mtlFileName)
+    {
+      PRINTF(4)("Not using new defined material, because no mtlFile found yet\n");
+      return false;
+    }
+      
+  if (this->currentGroup->faceCount >0)
+    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
+  this->initFace (this->currentGroup->currentFace);
+  
+  this->currentGroup->currentFace->materialString = new char[strlen(matString)+1];
+  strcpy (this->currentGroup->currentFace->materialString, matString);
+  
+  if (this->currentGroup->faceCount == 0)
+    this->currentGroup->faceCount ++;
+
+}
+
+/**
+   \brief reads and includes the Faces/Materials into the openGL state Machine
+*/
+bool Model::importToGL (void)
+{
+
+  // finalize the Arrays
+  this->vertices->finalizeArray();
+  this->vTexture->finalizeArray();
+  if (normals->getCount() == 0) // vertices-Array must be uilt for this
+    this->buildVertexNormals();
+  this->normals->finalizeArray();
+
+  this->currentGroup = this->firstGroup;
+
+  while (this->currentGroup != NULL)
+    {
+
+      // creating a glList for the Group
+      if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
+	{
+	  PRINTF(1)("list could not be created for this Model\n");
+	  return false;
+	}
+      glNewList (this->currentGroup->listNumber, GL_COMPILE);
+
+      // Putting Faces to GL
+      Face* tmpFace = this->currentGroup->firstFace;
+      while (tmpFace != NULL)
+	{
+	  if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL)
+	    {
+	      if (this->currentGroup->faceMode != -1)
+		glEnd();
+	      this->currentGroup->faceMode = 0;
+	      PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
+	      Material* tmpMat;
+	      if ((tmpMat = material->search(tmpFace->materialString)) != NULL)
+		tmpMat->select();
+
+	    }
+
+	  else if (tmpFace->vertexCount == 3)
+	    {
+	      if (this->currentGroup->faceMode != 3)
+		{
+		  if (this->currentGroup->faceMode != -1)
+		    glEnd();
+		  glBegin(GL_TRIANGLES);
+		}
+	      
+	      this->currentGroup->faceMode = 3;
+	      PRINTF(3)("found triag.\n");
+	    }
+	  
+	  else if (tmpFace->vertexCount == 4)
+	    {
+	      if (this->currentGroup->faceMode != 4)
+		{
+		  if (this->currentGroup->faceMode != -1)
+		    glEnd();
+		  glBegin(GL_QUADS);
+		}
+	      this->currentGroup->faceMode = 4;
+	      PRINTF(3)("found quad.\n");
+	    }
+	  
+	  else if (tmpFace->vertexCount > 4)
+	    {
+	      if (this->currentGroup->faceMode != -1)
+		glEnd();
+	      glBegin(GL_POLYGON);
+	      PRINTF(3)("Polygon with %i faces found.", tmpFace->vertexCount);
+	      this->currentGroup->faceMode = tmpFace->vertexCount;
+	    }
+	  
+	  FaceElement* tmpElem = tmpFace->firstElem;
+	  while (tmpElem != NULL)
+	    {
+	      //      PRINTF(2)("%s\n", tmpElem->value);
+	      this->addGLElement(tmpElem);
+	      tmpElem = tmpElem->next;
+	    }
+	  tmpFace = tmpFace->next;
+	}
+      glEnd();
+      glEndList();
+
+      this->currentGroup = this->currentGroup->next;
+    } 
+}
+
+/**
+   \brief Adds a Face-element (one vertex of a face) with all its information. 
+   \param elem The FaceElement to add to the OpenGL-environment.
+
+   It does this by searching:
+   1. The Vertex itself
+   2. The VertexNormale
+   3. The VertexTextureCoordinate
+   merging this information, the face will be drawn.
+*/
+bool Model::addGLElement (FaceElement* elem)
+{
+  PRINTF(3)("importing grafical Element to openGL.\n");
+
+  if (elem->texCoordNumber != -1)
+    glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
+  if (elem->normalNumber != -1)
+    glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
+  if (elem->vertexNumber != -1)
+    glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
+
+}
+
+/**
+   \brief A routine that is able to create normals.
+
+   The algorithm does the following:
+   1. It calculates creates Vectors for each normale, and sets them to zero.
+   2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
+   3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
+   4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
+*/
+bool Model::buildVertexNormals ()
+{
+  
+  PRINTF(2)("Normals are being calculated.\n");
+
+  Vector* normArray = new Vector [vertices->getCount()/3];
+  for (int i=0; i<vertices->getCount()/3;i++)
+    normArray[i] = Vector(.0,.0,.0);
+  
+  int firstTouch;
+  int secondTouch;
+  Vector prevV;
+  Vector nextV;
+  Vector curV;
+
+  Group* tmpGroup = firstGroup;
+  while (tmpGroup)
+    {
+      Face* tmpFace = tmpGroup->firstFace;
+      while (tmpFace)
+	{
+	  if (tmpFace->firstElem)
+	    {
+	      FaceElement* firstElem = tmpFace->firstElem;
+	      FaceElement* prevElem;
+	      FaceElement* curElem = firstElem;
+	      FaceElement* nextElem;
+	      FaceElement* lastElem;
+	      // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
+	      while (curElem)
+		{
+		  prevElem = curElem;
+		  curElem = curElem->next;
+		}
+	      lastElem = prevElem;
+	      
+	      curElem = firstElem;
+	      for (int j=0; j<tmpFace->vertexCount; j++)
+		{
+		  if (!(nextElem = curElem->next))
+		    nextElem = firstElem;
+		  curElem->normalNumber = curElem->vertexNumber;
+		  
+		  curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]);
+		  prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
+		  nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV;
+		  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
+
+		  prevElem = curElem;
+		  curElem = curElem->next;
+		}
+	    }
+	  tmpFace = tmpFace->next;
+	}
+      tmpGroup = tmpGroup->next;
+    }
+
+  for (int i=0; i<vertices->getCount()/3;i++)
+    {
+      normArray[i].normalize();
+      PRINTF(3)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
+
+      this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
+
+    }
+  delete []normArray; 
+  
+}
+
+
+/**
+   \brief Includes a default model
+
+   This will inject a Cube, because this is the most basic model.
+*/
+void Model::BoxModel(void)
+{
+  this->readVertex ("-0.5 -0.5 0.5");
+  this->readVertex ("0.5 -0.5 0.5");
+  this->readVertex ("-0.5 0.5 0.5");
+  this->readVertex ("0.5 0.5 0.5");
+  this->readVertex ("-0.5 0.5 -0.5");
+  this->readVertex ("0.5 0.5 -0.5");
+  this->readVertex ("-0.5 -0.5 -0.5");
+  this->readVertex ("0.5 -0.5 -0.5");
+
+  this->readVertexTexture ("0.0 0.0");
+  this->readVertexTexture ("1.0 0.0");
+  this->readVertexTexture ("0.0 1.0");
+  this->readVertexTexture ("1.0 1.0");
+  this->readVertexTexture ("0.0 2.0");
+  this->readVertexTexture ("1.0 2.0");
+  this->readVertexTexture ("0.0 3.0");
+  this->readVertexTexture ("1.0 3.0");
+  this->readVertexTexture ("0.0 4.0");
+  this->readVertexTexture ("1.0 4.0");
+  this->readVertexTexture ("2.0 0.0");
+  this->readVertexTexture ("2.0 1.0");
+  this->readVertexTexture ("-1.0 0.0");
+  this->readVertexTexture ("-1.0 1.0");
+
+  this->readVertexNormal ("0.0 0.0 1.0");
+  this->readVertexNormal ("0.0 0.0 1.0");
+  this->readVertexNormal ("0.0 0.0 1.0");
+  this->readVertexNormal ("0.0 0.0 1.0");
+  this->readVertexNormal ("0.0 1.0 0.0");
+  this->readVertexNormal ("0.0 1.0 0.0");
+  this->readVertexNormal ("0.0 1.0 0.0");
+  this->readVertexNormal ("0.0 1.0 0.0");
+  this->readVertexNormal ("0.0 0.0 -1.0");
+  this->readVertexNormal ("0.0 0.0 -1.0");
+  this->readVertexNormal ("0.0 0.0 -1.0");
+  this->readVertexNormal ("0.0 0.0 -1.0");
+  this->readVertexNormal ("0.0 -1.0 0.0");
+  this->readVertexNormal ("0.0 -1.0 0.0");
+  this->readVertexNormal ("0.0 -1.0 0.0");
+  this->readVertexNormal ("0.0 -1.0 0.0");
+  this->readVertexNormal ("1.0 0.0 0.0");
+  this->readVertexNormal ("1.0 0.0 0.0");
+  this->readVertexNormal ("1.0 0.0 0.0");
+  this->readVertexNormal ("1.0 0.0 0.0");
+  this->readVertexNormal ("-1.0 0.0 0.0");
+  this->readVertexNormal ("-1.0 0.0 0.0");
+  this->readVertexNormal ("-1.0 0.0 0.0");
+  this->readVertexNormal ("-1.0 0.0 0.0");
+
+  /* normaleLess-testingMode
+  this->readFace ("1 2 4 3");
+  this->readFace ("3 4 6 5");
+  this->readFace ("5 6 8 7");
+  this->readFace ("7 8 2 1");
+  this->readFace ("2 8 6 4");
+  this->readFace ("7 1 3 5");
+  */
+
+  this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4");
+  this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8");
+  this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12");
+  this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16");
+  this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20");
+  this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24");
+
+}
Index: orxonox/trunk/src/importer/model.h
===================================================================
--- orxonox/trunk/src/importer/model.h	(revision 3365)
+++ orxonox/trunk/src/importer/model.h	(revision 3365)
@@ -0,0 +1,122 @@
+/*!
+  \file model.h
+  \brief Contains the Model Class that handles 3D-Models
+*/
+
+#ifndef _MODEL_H
+#define _MODEL_H
+
+#include "../stdincl.h"
+
+#include "array.h"
+#include "material.h"
+#include "vector.h"
+#include <fstream>
+
+using namespace std;
+
+
+
+//! Class that handles 3D-Models. it can also read them in and display them.
+class Model
+{
+ public:
+  Model ();
+  Model (char* fileName);
+  Model(char* fileName, float scaling);
+  ~Model ();
+  
+  void draw (void) const;
+  void draw (int groupNumber) const;
+  void draw (char* groupName) const;
+  int getGroupCount() const;
+
+ private:
+  //! This is the placeholder of one Vertex beloning to a Face.
+  struct FaceElement 
+  {
+    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
+    int normalNumber;    //!< The number of the Normal out of the Array* normals, this vertex points to.
+    int texCoordNumber;  //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
+    FaceElement* next;   //!< Point to the next FaceElement in this List.
+  };
+
+  //! This is the placeholder of a Face belonging to a Group of Faces.
+  /**
+     \todo take Material to a call for itself.
+
+     This can also be a Material-Change switch. 
+     That means if you want to change a Material inside of a group,
+     you can create an empty face and apply a material to it, and the Importer will cahnge Colors
+  */
+  struct Face 
+  {
+    int vertexCount;        //!< The Count of vertices this Face has.
+    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
+
+    char* materialString;   //!< The Name of the Material to which to Change.
+
+    Face* next;             //!< Pointer to the next Face.
+  }; 
+
+  //! Group to handle multiple Models per obj-file.
+  struct Group
+  {
+    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
+
+    GLuint listNumber;  //!< The number of the GL-List this Group gets.
+    Face* firstFace;    //!< The first Face in this group.
+    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
+    int faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly \todo ENUM...
+    int faceCount;      //!< The Number of Faces this Group holds.
+
+    Group* next;        //!< Pointer to the next Group.
+  };
+
+
+  Array* vertices;      //!< The Array that handles the Vertices.
+  int verticesCount;    //!< A global Counter for vertices.
+  Array* normals;       //!< The Array that handles the Normals.
+  Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
+
+  
+  Group* firstGroup;    //!< The first of all groups.
+  Group* currentGroup;  //!< The currentGroup. this is the one we will work with.
+  int groupCount;       //!< The Count of Groups.
+
+  Material* material;   //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..)
+  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
+
+  char* objPath;        //!< The Path wher the obj and mtl-file are located.
+  char* objFileName;    //!< The Name of the obj-file.
+  char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
+
+  bool initialize (void);
+  bool initGroup(Group* group);
+  bool initFace (Face* face);
+  bool cleanup(void);
+  bool cleanupGroup(Group* group);
+  bool cleanupFace(Face* face);
+  bool cleanupFaceElement(FaceElement* faceElem);
+
+  ///// readin ///
+  bool importFile (char* fileName);
+  bool readFromObjFile (void);
+  
+  bool readGroup (char* groupString);
+  bool readVertex (char* vertexString);
+  bool readFace (char* faceString);
+  bool readVertexNormal (char* normalString);
+  bool readVertexTexture (char* vTextureString);
+  bool readMtlLib (char* matFile);
+  bool readUseMtl (char* mtlString);
+
+  bool importToGL (void);
+  bool addGLElement (FaceElement* elem);
+
+  bool buildVertexNormals ();
+
+  void BoxModel (void);
+};
+
+#endif
Index: orxonox/trunk/src/importer/object.cc
===================================================================
--- orxonox/trunk/src/importer/object.cc	(revision 3237)
+++ 	(revision )
@@ -1,977 +1,0 @@
-/* 
-   orxonox - the future of 3D-vertical-scrollers
-
-   Copyright (C) 2004 orx
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   ### File Specific:
-   main-programmer: Benjamin Grauer
-   co-programmer: ...
-*/
-
-#include "object.h"
-int verbose = 1; //! \todo should be GLOBAL
-using namespace std;
-
-/**
-   \brief Creates a 3D-Object, but does not load any 3D-models.
-
-   This Constructor is pretty useless, because why load no object in an object-loader??
-*/
-Object::Object ()
-{
-
-  this->initialize();
-
-  this->BoxObject();
-
-  this->importToGL ();
-
-  this->cleanup();
-}
-
-/**
-   \brief Crates a 3D-Object and loads in a File.
-   \param fileName file to parse and load (must be a .obj file)
-*/
-Object::Object(char* fileName)
-{
-  this->initialize();
-
-  this->importFile (fileName);
-
-  this->importToGL ();
-
-  this->cleanup();
-}
-
-/**
-   \brief Crates a 3D-Object, loads in a File and scales it.
-   \param fileName file to parse and load (must be a .obj file)
-   \param scaling The factor that the object will be scaled with.
-*/
-Object::Object(char* fileName, float scaling)
-{
-  this->initialize();
-  this->scaleFactor = scaling;
-
-  this->importFile (fileName);
-
-  this->importToGL ();
-
-  this->cleanup();
-}
-
-/**
-   \brief deletes an Object.
-
-   Looks if any from object allocated space is still in use, and if so deleted it.
-*/
-Object::~Object()
-{
-  PRINTF(2)("Deleting display Lists.\n");
-  Group* walker = this->firstGroup;
-  while (walker != NULL)
-    {
-      glDeleteLists (walker->listNumber, 1);
-      Group* delWalker = walker;
-      walker = walker->next;
-      delete delWalker;
-    }
-
-  if (this->objPath)
-    delete []this->objPath;
-  if (this->objFileName)
-    delete []this->objFileName;
-  if (this->mtlFileName)
-    delete []this->mtlFileName;
-  PRINTF(2)("Deleting Materials.\n");
-  if (this->material)
-    delete this->material;
-}
-
-
-/**
-   \brief Draws the Objects of all Groups.
-   It does this by just calling the Lists that must have been created earlier.
-*/
-void Object::draw (void) const
-{
-  PRINTF(2)("drawing the 3D-Objects\n"); 
-  Group* walker = this->firstGroup;
-  while (walker != NULL)
-    {
-      PRINTF(3)("Drawing object %s\n", walker->name);
-      glCallList (walker->listNumber);
-      walker = walker->next;
-    }
-}
-
-/**
-   \brief Draws the Object number groupNumber
-   \param groupNumber The number of the group that will be displayed.
-
-   It does this by just calling the List that must have been created earlier.
-*/
-void Object::draw (int groupNumber) const 
-{
-  if (groupNumber >= this->groupCount)
-    {
-      PRINTF(1)("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, this->groupCount);
-      return;
-    }
-  PRINTF(2)("drawing the requested 3D-Objects if found.\n"); 
-  Group* walker = this->firstGroup;
-  int counter = 0;
-  while (walker != NULL)
-    {
-      if (counter == groupNumber)
-	{
-	  PRINTF(2)("Drawing object number %i named %s\n", counter, walker->name);
-	  glCallList (walker->listNumber);
-	  return;
-	}
-      ++counter;
-      walker = walker->next;
-    }
-  PRINTF(1)("Object number %i in %s not Found.\n", groupNumber, this->objFileName);
-  return;
-
-}
-
-/**
-   \brief Draws the Object with a specific groupName
-   \param groupName The name of the group that will be displayed.
-
-   It does this by just calling the List that must have been created earlier.
-*/
-void Object::draw (char* groupName) const
-{
-  PRINTF(2)("drawing the requested 3D-Objects if found.\n"); 
-  Group* walker = this->firstGroup;
-  while (walker != NULL)
-    {
-      if (!strcmp(walker->name, groupName))
-	{
-	  PRINTF(2)("Drawing object %s\n", walker->name);
-	  glCallList (walker->listNumber);
-	  return;
-	}
-      walker = walker->next;
-    }
-  PRINTF(1)("Object Named %s in %s not Found.\n", groupName, this->objFileName);
-  return;
-}
-
-/**
-   \returns Count of the Objects in this File
-*/
-int Object::getGroupCount (void) const
-{
-  return this->groupCount;
-}
-
-/**
-    \brief initializes the Object.
-
-    This Function initializes all the needed arrays, Lists and clientStates.
-    It also defines default values.
-*/
-bool Object::initialize (void)
-{
-  PRINTF(2)("new 3D-Object is being created\n"); 
-
-  // setting the start group;
-  this->firstGroup = new Group;
-  this->currentGroup = this->firstGroup;
-  this->groupCount = 0;
-  
-  this->initGroup (this->currentGroup);
-  this->objPath = NULL;
-  this->objFileName = NULL;
-  this->mtlFileName = NULL;
-  this->scaleFactor = 1;
-  this->material = new Material();
-
-  this->vertices = new Array();
-  this->vTexture = new Array();
-  this->normals = new Array();
-
-  return true;
-}
-
-/**
-   \brief initializes a new Group object
-   \param group the group that should be initialized.
-   \todo Maybe Group should be a Class, because it does a lot of stuff
-   
-*/
-bool Object::initGroup(Group* group)
-{
-  PRINTF(3)("Adding new Group\n");
-  group->name = "";
-  group->faceMode = -1;
-  group->faceCount = 0;  
-  group->next = NULL;
-
-  group->firstFace = new Face;
-  this->initFace (group->firstFace);
-  group->currentFace = group->firstFace;
-}
-
-/**
-   \brief initializes a new Face. (sets default Values)
-   \param face The face to initialize
-*/
-bool Object::initFace (Face* face)
-{
-  face->vertexCount = 0;
-
-  face->firstElem = NULL;
-  
-  face->materialString = NULL;
-  
-  face->next = NULL;
-
-  return true;
-}
-
-/**
-   \brief finalizes an Object.
-   This funcion is needed, to delete all the Lists, and arrays that are no more needed because they are already imported into openGL. This will be applied at the end of the importing Process.
-*/
-bool Object::cleanup(void)
-{
-  PRINTF(3)("cleaning up the 3D-Object to save Memory.\n");
-
-  if (this->vertices)
-    delete this->vertices;
-  if (this->vTexture)
-    delete this->vTexture;
-  if (this->normals)
-    delete this->normals;
-
-  this->cleanupGroup(this->firstGroup);
-  return true; 
-}
-
-/**
-   \brief Cleans up all groups starting from group.
-   \param group the first Group to clean
-*/
-bool Object::cleanupGroup (Group* group)
-{
-  PRINTF(3)("Cleaning up group\n");
-  if (group->firstFace != NULL)
-    {
-      cleanupFace (group->firstFace);
-      delete group->firstFace;
-    }
-
-  if (group->next !=NULL)
-    cleanupGroup (group->next);
-  return true;
-}
-
-/**
-   \brief Cleans up all Faces starting from face until NULL is reached.
-   \param face the first face to clean.
-*/
-bool Object::cleanupFace (Face* face)
-{
-  PRINTF(3)("Cleaning up Face\n");
-
-  if (face->materialString != NULL)
-      delete []face->materialString;
-  if (face->firstElem != NULL)
-    {
-      this->cleanupFaceElement(face->firstElem);
-      delete face->firstElem;
-    }
-      
-  if (face->next != NULL)
-    {
-      this->cleanupFace (face->next);
-      delete face->next;
-    }
-      
-}
-
-
-/**
-   \brief Cleans up all FaceElements starting from faceElem.
-   \param faceElem the first FaceElement to clean.
-*/
-bool Object::cleanupFaceElement(FaceElement* faceElem)
-{
-  if (faceElem->next != NULL)
-    {
-      this->cleanupFaceElement (faceElem->next);
-      delete faceElem->next;
-    }
-}
-
-/**
-   \brief Imports a obj file and handles the the relative location
-   \param fileName The file to import
-*/
-bool Object::importFile (char* fileName)
-{
-  PRINTF(3)("preparing to read in file: %s\n", fileName);
-
-
-#ifdef __WIN32__
-  // win32 path reading
-  char pathSplitter= '\\';
-#else /* __WIN32__ */
-  // unix path reading
-  char pathSplitter='/';
-#endif /* __WIN32__ */
-  char* tmpName = fileName;
-  if (tmpName[0] == pathSplitter)
-    tmpName++;
-  char* name = tmpName;
-  while (( tmpName = strchr (tmpName+1, pathSplitter)))
-    {
-      name = tmpName+1;
-    }
-  this->objPath = new char[name-fileName];
-  strncpy(this->objPath, fileName, name-fileName);
-  this->objPath[name-fileName] = '\0';
-  if (verbose >=2)
-    if (strlen(objPath)> 0)
-      PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath);
-    else
-      PRINTF(0)("Resolved file %s.\n", name);
-  
-  if (this->material)
-    this->material->addTexturePath(this->objPath);
-  this->objFileName = new char[strlen(name)+1];
-  strcpy (this->objFileName, name);
-  this->readFromObjFile ();
-  return true;
-}
-
-/**
-   \brief Reads in the .obj File and sets all the Values.
-   This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
-*/
-bool Object::readFromObjFile (void)
-{
-  char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
-  if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
-    return false;
-  strcpy(fileName, this->objPath);
-  strcat(fileName, this->objFileName);
-
-  ifstream* OBJ_FILE = new ifstream(fileName);
-  if (OBJ_FILE->fail())
-    {
-      PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Object instead.\n", fileName);
-      BoxObject();
-      OBJ_FILE->close();
-      delete []fileName;
-      delete OBJ_FILE;
-      return false;
-    }
-  PRINTF(2)("Reading from opened file %s\n", fileName);
-  char Buffer[10000];
-  while(!OBJ_FILE->eof())
-    {
-      OBJ_FILE->getline(Buffer, 10000);
-      PRINTF(3)("Read input line: %s\n", Buffer);
-      
-
-      // case vertice
-      if (!strncmp(Buffer, "v ", 2))
-	{
-	  this->readVertex(Buffer+2);
-	}
-
-      // case face
-      else if (!strncmp(Buffer, "f ", 2))
-	{
-	  this->readFace (Buffer+2);
-	}
-      
-      else if (!strncmp(Buffer, "mtllib ", 7))
-	{
-	  this->readMtlLib (Buffer+7);
-	}
-
-      else if (!strncmp(Buffer, "usemtl ", 7))
-	{
-	  this->readUseMtl (Buffer+7);
-	}
-
-      // case VertexNormal
-      else if (!strncmp(Buffer, "vn ", 3))
-	{
-	  this->readVertexNormal(Buffer+3);
-	}
-      
-      // case VertexTextureCoordinate
-      else if (!strncmp(Buffer, "vt ", 3))
-	{
-	  this->readVertexTexture(Buffer+3);
-	}
-      // case group
-      else if (!strncmp(Buffer, "g ", 2))
-	{
-	  this->readGroup (Buffer+2);
-	}
-      else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented
-	{
-	  if (verbose >= 2)
-	    PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer);
-	}
-    }
-  OBJ_FILE->close();
-  delete OBJ_FILE;
-  delete []fileName;
-  return true;
-
-}
-
-/**
-   \brief parses a group String
-   \param groupString the new Group to create
-
-   This function initializes a new Group. 
-   With it you should be able to import .obj-files with more than one Objects inside. 
-*/
-bool Object::readGroup (char* groupString)
-{
-  PRINTF(3)("Read Group: %s.\n", groupString);
-  if (this->groupCount != 0 && this->currentGroup->faceCount>0)
-    {
-      //      finalizeGroup(currentGroup);
-      this->currentGroup = this->currentGroup->next = new Group;
-      this->initGroup(this->currentGroup);
-    }
-  // setting the group name if not default.
-  if (strcmp(groupString, "default"))
-    {
-      this->currentGroup->name = new char [strlen(groupString)+1];
-      strcpy(this->currentGroup->name, groupString);
-    }
-  ++this->groupCount;
-
-}
-
-/**
-   \brief parses a vertex-String
-   \param vertexString The String that will be parsed.
-
-   If a vertex line is found this function will inject it into the vertex-Array
-*/
-bool Object::readVertex (char* vertexString)
-{
-  float subbuffer1;
-  float subbuffer2;
-  float subbuffer3;
-  sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
-  PRINTF(3)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
-  this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
-  return true;
-}
-
-/**
-   \brief parses a face-string
-   \param faceString The String that will be parsed.
-
-   If a face line is found this function will add it to the glList.
-   The function makes a difference between QUADS and TRIANGLES, and will if changed re-open, set and re-close the gl-processe.
-*/
-bool Object::readFace (char* faceString)
-{
-  if (this->currentGroup->faceCount >0)
-    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
-  this->initFace (this->currentGroup->currentFace);
-
-  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
-  tmpElem->next = NULL;
-  while(strcmp (faceString, "\0"))
-    {
-      if (this->currentGroup->currentFace->vertexCount>0)
-	  tmpElem = tmpElem->next = new FaceElement;
-      tmpElem->next = NULL;
-
-      char tmpValue [50];
-      int tmpLen;
-      char* vertex = NULL;
-      char* texture = NULL;
-      char* normal = NULL;
-
-      sscanf (faceString, "%s", tmpValue);
-      tmpLen = strlen(tmpValue);
-      vertex = tmpValue;
-
-      if ((texture = strstr (vertex, "/")) != NULL)
-	{
-	  texture[0] = '\0';
-	  texture ++;
-	  
-	  if ((normal = strstr (texture, "/")) !=NULL)
-	    {
-	      normal[0] = '\0';
-	      normal ++;
-	    }	  
-	}
-      if (vertex)
-	tmpElem->vertexNumber = atoi(vertex)-1;
-      else
-	tmpElem->vertexNumber = -1;
-      if (texture)
-	tmpElem->texCoordNumber = atoi(texture)-1;
-      else
-	tmpElem->texCoordNumber = -1;
-      if (normal)
-	tmpElem->normalNumber = atoi(normal)-1;
-      else
-	tmpElem->normalNumber = -1;
-
-      faceString += tmpLen;
-      if (strcmp (faceString, "\0"))
-	faceString++;
-      this->currentGroup->currentFace->vertexCount++;
-    }
-
-  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
-}
-
-/**
-   \brief parses a vertexNormal-String
-   \param normalString The String that will be parsed.
-
-   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
-*/
-bool Object::readVertexNormal (char* normalString)
-{
-  float subbuffer1;
-  float subbuffer2;
-  float subbuffer3;
-  sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
-  PRINTF(3)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
-  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
-  return true;
-}
-
-/**
-   \brief parses a vertexTextureCoordinate-String
-   \param vTextureString The String that will be parsed.
-
-   If a vertexTextureCoordinate line is found,
-   this function will inject it into the vertexTexture-Array
-*/
-bool Object::readVertexTexture (char* vTextureString)
-{
-  float subbuffer1;
-  float subbuffer2;
-  sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
-  PRINTF(3)("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2);
-  this->vTexture->addEntry(subbuffer1);
-  this->vTexture->addEntry(subbuffer2);
-  return true;
-}
-
-/** 
-    \brief Function to read in a mtl File.
-    \param mtlFile The .mtl file to read
-
-    This Function parses all Lines of an mtl File.
-    The reason for it not to be in the materials-class is,
-    that a material does not have to be able to read itself in from a File.
-
-*/
-bool Object::readMtlLib (char* mtlFile)
-{
-  this->mtlFileName = new char [strlen(mtlFile)+1];
-  strcpy(this->mtlFileName, mtlFile);
-  char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
-  strcpy(fileName, this->objPath);
-  strcat(fileName, this->mtlFileName);
-  
-
-  PRINTF(2)("Opening mtlFile: %s\n", fileName);
-
-  ifstream* MTL_FILE = new ifstream (fileName);
-  if (MTL_FILE->fail())
-    {
-      if (verbose >= 1)
-	PRINTF(2)("unable to open file: %s\n", fileName);
-      MTL_FILE->close();
-      delete []fileName;
-      delete MTL_FILE;
-      return false;
-    }
-  char Buffer[500];
-  Material* tmpMat = material;
-  while(!MTL_FILE->eof())
-    {
-      MTL_FILE->getline(Buffer, 500);
-      PRINTF(4)("found line in mtlFile: %s\n", Buffer);
-      
-
-      // create new Material
-      if (!strncmp(Buffer, "newmtl ", 7))
-	{
-	  tmpMat = tmpMat->addMaterial(Buffer+7);
-	  //	  PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat);
-	}
-      // setting a illumMode
-      else if (!strncmp(Buffer, "illum ", 6))
-	{
-	  tmpMat->setIllum(Buffer+6);
-
-	}
-      // setting Diffuse Color
-      else if (!strncmp(Buffer, "Kd ", 3))
-	{
-	  tmpMat->setDiffuse(Buffer+3);
-	}
-      // setting Ambient Color
-      else if (!strncmp(Buffer, "Ka ", 3))
-	{
-	  tmpMat->setAmbient(Buffer+3);
-	}
-      // setting Specular Color
-      else if (!strncmp(Buffer, "Ks ", 3))
-	{
-	  tmpMat->setSpecular(Buffer+3);
-	}
-      // setting The Specular Shininess
-      else if (!strncmp(Buffer, "Ns ", 3))
-	{
-	  tmpMat->setShininess(Buffer+3);
-	}
-      // setting up transparency
-      else if (!strncmp(Buffer, "d ", 2))
-	{
-	  tmpMat->setTransparency(Buffer+2);
-	}
-      else if (!strncmp(Buffer, "Tf ", 3))
-	{
-	  tmpMat->setTransparency(Buffer+3);
-	}
-      
-      else if (!strncmp(Buffer, "map_Kd ", 7))
-	{
-	  tmpMat->setDiffuseMap(Buffer+7);
-	}
-      else if (!strncmp(Buffer, "map_Ka ", 7))
-	{
-	  tmpMat->setAmbientMap(Buffer+7);
-	}
-      else if (!strncmp(Buffer, "map_Ks ", 7))
-	{
-	  tmpMat->setSpecularMap(Buffer+7);
-	}
-      else if (!strncmp(Buffer, "bump ", 5))
-	{
-	  tmpMat->setBump(Buffer+7);
-	}
-     
-
-    }
-  MTL_FILE->close();
-  delete []fileName;
-  delete MTL_FILE;
-  return true;
-}
-
-/**
-   \brief Function that selects a material, if changed in the obj file.
-   \param matString the Material that will be set.
-*/
-bool Object::readUseMtl (char* matString)
-{
-  if (!this->mtlFileName)
-    {
-      PRINTF(4)("Not using new defined material, because no mtlFile found yet\n");
-      return false;
-    }
-      
-  if (this->currentGroup->faceCount >0)
-    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
-  this->initFace (this->currentGroup->currentFace);
-  
-  this->currentGroup->currentFace->materialString = new char[strlen(matString)+1];
-  strcpy (this->currentGroup->currentFace->materialString, matString);
-  
-  if (this->currentGroup->faceCount == 0)
-    this->currentGroup->faceCount ++;
-
-}
-
-/**
-   \brief reads and includes the Faces/Materials into the openGL state Machine
-*/
-bool Object::importToGL (void)
-{
-
-  // finalize the Arrays
-  this->vertices->finalizeArray();
-  this->vTexture->finalizeArray();
-  if (normals->getCount() == 0) // vertices-Array must be uilt for this
-    this->buildVertexNormals();
-  this->normals->finalizeArray();
-
-  this->currentGroup = this->firstGroup;
-
-  while (this->currentGroup != NULL)
-    {
-
-      // creating a glList for the Group
-      if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
-	{
-	  PRINTF(1)("list could not be created for this Object\n");
-	  return false;
-	}
-      glNewList (this->currentGroup->listNumber, GL_COMPILE);
-
-      // Putting Faces to GL
-      Face* tmpFace = this->currentGroup->firstFace;
-      while (tmpFace != NULL)
-	{
-	  if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL)
-	    {
-	      if (this->currentGroup->faceMode != -1)
-		glEnd();
-	      this->currentGroup->faceMode = 0;
-	      PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
-	      Material* tmpMat;
-	      if ((tmpMat = material->search(tmpFace->materialString)) != NULL)
-		tmpMat->select();
-
-	    }
-
-	  else if (tmpFace->vertexCount == 3)
-	    {
-	      if (this->currentGroup->faceMode != 3)
-		{
-		  if (this->currentGroup->faceMode != -1)
-		    glEnd();
-		  glBegin(GL_TRIANGLES);
-		}
-	      
-	      this->currentGroup->faceMode = 3;
-	      PRINTF(3)("found triag.\n");
-	    }
-	  
-	  else if (tmpFace->vertexCount == 4)
-	    {
-	      if (this->currentGroup->faceMode != 4)
-		{
-		  if (this->currentGroup->faceMode != -1)
-		    glEnd();
-		  glBegin(GL_QUADS);
-		}
-	      this->currentGroup->faceMode = 4;
-	      PRINTF(3)("found quad.\n");
-	    }
-	  
-	  else if (tmpFace->vertexCount > 4)
-	    {
-	      if (this->currentGroup->faceMode != -1)
-		glEnd();
-	      glBegin(GL_POLYGON);
-	      PRINTF(3)("Polygon with %i faces found.", tmpFace->vertexCount);
-	      this->currentGroup->faceMode = tmpFace->vertexCount;
-	    }
-	  
-	  FaceElement* tmpElem = tmpFace->firstElem;
-	  while (tmpElem != NULL)
-	    {
-	      //      PRINTF(2)("%s\n", tmpElem->value);
-	      this->addGLElement(tmpElem);
-	      tmpElem = tmpElem->next;
-	    }
-	  tmpFace = tmpFace->next;
-	}
-      glEnd();
-      glEndList();
-
-      this->currentGroup = this->currentGroup->next;
-    } 
-}
-
-/**
-   \brief Adds a Face-element (one vertex of a face) with all its information. 
-   \param elem The FaceElement to add to the OpenGL-environment.
-
-   It does this by searching:
-   1. The Vertex itself
-   2. The VertexNormale
-   3. The VertexTextureCoordinate
-   merging this information, the face will be drawn.
-*/
-bool Object::addGLElement (FaceElement* elem)
-{
-  PRINTF(3)("importing grafical Element to openGL.\n");
-
-  if (elem->texCoordNumber != -1)
-    glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
-  if (elem->normalNumber != -1)
-    glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
-  if (elem->vertexNumber != -1)
-    glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
-
-}
-
-/**
-   \brief A routine that is able to create normals.
-
-   The algorithm does the following:
-   1. It calculates creates Vectors for each normale, and sets them to zero.
-   2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements
-   3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal.
-   4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array.
-*/
-bool Object::buildVertexNormals ()
-{
-  
-  PRINTF(2)("Normals are being calculated.\n");
-
-  Vector* normArray = new Vector [vertices->getCount()/3];
-  for (int i=0; i<vertices->getCount()/3;i++)
-    normArray[i] = Vector(.0,.0,.0);
-  
-  int firstTouch;
-  int secondTouch;
-  Vector prevV;
-  Vector nextV;
-  Vector curV;
-
-  Group* tmpGroup = firstGroup;
-  while (tmpGroup)
-    {
-      Face* tmpFace = tmpGroup->firstFace;
-      while (tmpFace)
-	{
-	  if (tmpFace->firstElem)
-	    {
-	      FaceElement* firstElem = tmpFace->firstElem;
-	      FaceElement* prevElem;
-	      FaceElement* curElem = firstElem;
-	      FaceElement* nextElem;
-	      FaceElement* lastElem;
-	      // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
-	      while (curElem)
-		{
-		  prevElem = curElem;
-		  curElem = curElem->next;
-		}
-	      lastElem = prevElem;
-	      
-	      curElem = firstElem;
-	      for (int j=0; j<tmpFace->vertexCount; j++)
-		{
-		  if (!(nextElem = curElem->next))
-		    nextElem = firstElem;
-		  curElem->normalNumber = curElem->vertexNumber;
-		  
-		  curV = Vector (vertices->getArray()[curElem->vertexNumber*3], vertices->getArray()[curElem->vertexNumber*3+1], vertices->getArray()[curElem->vertexNumber*3+2]);
-		  prevV = Vector (vertices->getArray()[prevElem->vertexNumber*3], vertices->getArray()[prevElem->vertexNumber*3+1], vertices->getArray()[prevElem->vertexNumber*3+2]) - curV;
-		  nextV = Vector (vertices->getArray()[nextElem->vertexNumber*3], vertices->getArray()[nextElem->vertexNumber*3+1], vertices->getArray()[nextElem->vertexNumber*3+2]) - curV;
-		  normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
-
-		  prevElem = curElem;
-		  curElem = curElem->next;
-		}
-	    }
-	  tmpFace = tmpFace->next;
-	}
-      tmpGroup = tmpGroup->next;
-    }
-
-  for (int i=0; i<vertices->getCount()/3;i++)
-    {
-      normArray[i].normalize();
-      PRINTF(3)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
-
-      this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
-
-    }
-  delete []normArray; 
-  
-}
-
-
-/**
-   \brief Includes a default object
-
-   This will inject a Cube, because this is the most basic object.
-*/
-void Object::BoxObject(void)
-{
-  this->readVertex ("-0.5 -0.5 0.5");
-  this->readVertex ("0.5 -0.5 0.5");
-  this->readVertex ("-0.5 0.5 0.5");
-  this->readVertex ("0.5 0.5 0.5");
-  this->readVertex ("-0.5 0.5 -0.5");
-  this->readVertex ("0.5 0.5 -0.5");
-  this->readVertex ("-0.5 -0.5 -0.5");
-  this->readVertex ("0.5 -0.5 -0.5");
-
-  this->readVertexTexture ("0.0 0.0");
-  this->readVertexTexture ("1.0 0.0");
-  this->readVertexTexture ("0.0 1.0");
-  this->readVertexTexture ("1.0 1.0");
-  this->readVertexTexture ("0.0 2.0");
-  this->readVertexTexture ("1.0 2.0");
-  this->readVertexTexture ("0.0 3.0");
-  this->readVertexTexture ("1.0 3.0");
-  this->readVertexTexture ("0.0 4.0");
-  this->readVertexTexture ("1.0 4.0");
-  this->readVertexTexture ("2.0 0.0");
-  this->readVertexTexture ("2.0 1.0");
-  this->readVertexTexture ("-1.0 0.0");
-  this->readVertexTexture ("-1.0 1.0");
-
-  this->readVertexNormal ("0.0 0.0 1.0");
-  this->readVertexNormal ("0.0 0.0 1.0");
-  this->readVertexNormal ("0.0 0.0 1.0");
-  this->readVertexNormal ("0.0 0.0 1.0");
-  this->readVertexNormal ("0.0 1.0 0.0");
-  this->readVertexNormal ("0.0 1.0 0.0");
-  this->readVertexNormal ("0.0 1.0 0.0");
-  this->readVertexNormal ("0.0 1.0 0.0");
-  this->readVertexNormal ("0.0 0.0 -1.0");
-  this->readVertexNormal ("0.0 0.0 -1.0");
-  this->readVertexNormal ("0.0 0.0 -1.0");
-  this->readVertexNormal ("0.0 0.0 -1.0");
-  this->readVertexNormal ("0.0 -1.0 0.0");
-  this->readVertexNormal ("0.0 -1.0 0.0");
-  this->readVertexNormal ("0.0 -1.0 0.0");
-  this->readVertexNormal ("0.0 -1.0 0.0");
-  this->readVertexNormal ("1.0 0.0 0.0");
-  this->readVertexNormal ("1.0 0.0 0.0");
-  this->readVertexNormal ("1.0 0.0 0.0");
-  this->readVertexNormal ("1.0 0.0 0.0");
-  this->readVertexNormal ("-1.0 0.0 0.0");
-  this->readVertexNormal ("-1.0 0.0 0.0");
-  this->readVertexNormal ("-1.0 0.0 0.0");
-  this->readVertexNormal ("-1.0 0.0 0.0");
-
-  /* normaleLess-testingMode
-  this->readFace ("1 2 4 3");
-  this->readFace ("3 4 6 5");
-  this->readFace ("5 6 8 7");
-  this->readFace ("7 8 2 1");
-  this->readFace ("2 8 6 4");
-  this->readFace ("7 1 3 5");
-  */
-
-  this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4");
-  this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8");
-  this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12");
-  this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16");
-  this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20");
-  this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24");
-
-}
Index: orxonox/trunk/src/importer/object.h
===================================================================
--- orxonox/trunk/src/importer/object.h	(revision 3237)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/*!
-  \file object.h
-  \brief Contains the Object Class that handles 3D-Objects
-*/
-
-#ifndef _OBJECT_H
-#define _OBJECT_H
-
-#include "../stdincl.h"
-
-#include "array.h"
-#include "material.h"
-#include "vector.h"
-#include <fstream>
-
-using namespace std;
-
-
-
-//! Class that handles 3D-Objects. it can also read them in and display them.
-class Object
-{
- public:
-  Object ();
-  Object (char* fileName);
-  Object(char* fileName, float scaling);
-  ~Object ();
-  
-  void draw (void) const;
-  void draw (int groupNumber) const;
-  void draw (char* groupName) const;
-  int getGroupCount() const;
-
- private:
-  //! This is the placeholder of one Vertex beloning to a Face.
-  struct FaceElement 
-  {
-    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
-    int normalNumber;    //!< The number of the Normal out of the Array* normals, this vertex points to.
-    int texCoordNumber;  //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.
-    FaceElement* next;   //!< Point to the next FaceElement in this List.
-  };
-
-  //! This is the placeholder of a Face belonging to a Group of Faces.
-  /**
-     \todo take Material to a call for itself.
-
-     This can also be a Material-Change switch. 
-     That means if you want to change a Material inside of a group,
-     you can create an empty face and apply a material to it, and the Importer will cahnge Colors
-  */
-  struct Face 
-  {
-    int vertexCount;        //!< The Count of vertices this Face has.
-    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
-
-    char* materialString;   //!< The Name of the Material to which to Change.
-
-    Face* next;             //!< Pointer to the next Face.
-  }; 
-
-  //! Group to handle multiple Objects per obj-file.
-  struct Group
-  {
-    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
-
-    GLuint listNumber;  //!< The number of the GL-List this Group gets.
-    Face* firstFace;    //!< The first Face in this group.
-    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
-    int faceMode;       //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material,  3 for triangle, 4 for Quad, 5+ for Poly \todo ENUM...
-    int faceCount;      //!< The Number of Faces this Group holds.
-
-    Group* next;        //!< Pointer to the next Group.
-  };
-
-
-  Array* vertices;      //!< The Array that handles the Vertices.
-  int verticesCount;    //!< A global Counter for vertices.
-  Array* normals;       //!< The Array that handles the Normals.
-  Array* vTexture;      //!< The Array that handles the VertexTextureCoordinates.
-
-  
-  Group* firstGroup;    //!< The first of all groups.
-  Group* currentGroup;  //!< The currentGroup. this is the one we will work with.
-  int groupCount;       //!< The Count of Groups.
-
-  Material* material;   //!< Initial pointer to the Material. This can hold many materials, because Material can be added with Material::addMaterial(..)
-  float scaleFactor;    //!< The Factor with which the Object hould be scaled. \todo maybe one wants to scale the Object after Initialisation
-
-  char* objPath;        //!< The Path wher the obj and mtl-file are located.
-  char* objFileName;    //!< The Name of the obj-file.
-  char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
-
-  bool initialize (void);
-  bool initGroup(Group* group);
-  bool initFace (Face* face);
-  bool cleanup(void);
-  bool cleanupGroup(Group* group);
-  bool cleanupFace(Face* face);
-  bool cleanupFaceElement(FaceElement* faceElem);
-
-  ///// readin ///
-  bool importFile (char* fileName);
-  bool readFromObjFile (void);
-  
-  bool readGroup (char* groupString);
-  bool readVertex (char* vertexString);
-  bool readFace (char* faceString);
-  bool readVertexNormal (char* normalString);
-  bool readVertexTexture (char* vTextureString);
-  bool readMtlLib (char* matFile);
-  bool readUseMtl (char* mtlString);
-
-  bool importToGL (void);
-  bool addGLElement (FaceElement* elem);
-
-  bool buildVertexNormals ();
-
-  void BoxObject (void);
-};
-
-#endif
Index: orxonox/trunk/src/importer/texture.cc
===================================================================
--- orxonox/trunk/src/importer/texture.cc	(revision 3365)
+++ orxonox/trunk/src/importer/texture.cc	(revision 3365)
@@ -0,0 +1,956 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+
+   TGA-code: borrowed from nehe-Tutorials
+
+*/
+
+
+#include "texture.h"
+
+// headers only for PathList
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fstream>
+
+/**
+   \brief creates a ned PathList.
+   
+   It is a good idea to use this as an initial List,
+   because if you give on a name the Path will not be checked for its existence.
+*/
+PathList::PathList()
+{
+  this->pathName = NULL;
+  this->next = NULL;
+}
+
+/**
+   \brief Creates a new PathList with a Name.
+   \param pName the Name of The Path.
+
+   This function just adds the Path without checking if it exists.
+*/
+PathList::PathList(char* pName)
+{
+  this->pathName = new char [strlen(pName)+1];
+  strcpy (this->pathName, pName);
+  this->next = NULL;
+}
+
+/**
+   \brief destroys a PathList
+
+   It does this by deleting the Name and then delete its preceding PathList.
+*/
+PathList::~PathList()
+{
+  if (this->pathName)
+    delete []this->pathName;
+  if (this->next)
+    delete this->next;
+}
+
+PathList* PathList::firstPath = NULL;
+
+/**
+   \returns A Pointer to the first Path of the Pathlist
+*/
+PathList* PathList::getInstance(void)
+{
+  if (firstPath)
+    return firstPath;
+  firstPath = new PathList();
+}
+/**
+   \brief Adds a new Pathlist Element.
+   \param pName
+   
+   Adding a Path automatically checks if the Path exists,
+   and if it does not it will not add it to the List.
+*/
+void PathList::addPath (char* pName)
+{
+  if (pName[0] == '\0')
+    {
+      PRINTF(3)("not Adding empty Path to the List.\n");
+      return;
+    }
+  char* tmpPName = new char[strlen(pName)];
+  strncpy(tmpPName, pName, strlen(pName)-1);
+  tmpPName[strlen(pName)-1] = '\0';
+  if (access (tmpPName, F_OK) == 0)
+    {
+      struct stat status;
+      stat(tmpPName, &status);
+      if (status.st_mode & S_IFDIR)
+	{
+	  PRINTF(2)("Adding Path %s to the PathList.\n", pName);
+	  PathList* tmpPathList = this;
+	  while (tmpPathList->next)
+	    tmpPathList = tmpPathList->next;
+	  tmpPathList->next = new PathList(pName);
+	}
+      else
+	PRINTF(2)("You tried to add non-folder %s to a PathList.\n", tmpPName);
+    }
+  else
+      PRINTF(2)("You tried to add non-existing folder %s to a PathList.\n", tmpPName);
+  delete []tmpPName;
+}
+
+
+
+/**
+   \brief Constructor for a Texture
+*/
+Texture::Texture(void)
+{
+  this->pImage = new Image;
+  this->pImage->data = NULL;
+  this->map = 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);
+}
+
+/**
+   \brief Searches for a Texture inside one of the defined Paths
+   \param texName The name of the texture o search for.
+   \returns pathName+texName if texName was found in the pathList. NULL if the Texture is not found.
+*/
+char* Texture::searchTextureInPaths(char* texName) const
+{
+  char* tmpName = NULL;
+  PathList* pList = PathList::getInstance();
+  while (pList)
+    {
+      if (pList->pathName)
+	{
+	  tmpName = new char [strlen(pList->pathName)+strlen(texName)+1];
+	  strcpy(tmpName, pList->pathName);
+	}
+      else
+	{
+	  tmpName = new char [strlen(texName)+1];
+	  tmpName[0]='\0';
+	}
+      strcat(tmpName, texName);
+      if (access (tmpName, F_OK) == 0)
+	return tmpName;
+      
+      if (tmpName)
+	delete []tmpName;
+      tmpName = NULL;
+      pList = pList->next;
+    }
+  return NULL;
+}
+
+/**
+   \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)
+{
+  unsigned char temp;
+  temp = a;
+  a    = b;
+  b    = temp;
+}
+
+
+/**
+   \brief Loads a Texture to the openGL-environment.
+   \param pImage The Image to load to openGL
+   \param texture The Texture to apply it to.
+*/
+bool Texture::loadTexToGL (Image* pImage)
+{
+  PRINTF(2)("Loading texture to OpenGL-Environment.\n");
+  glGenTextures(1, &this->texture);
+  glBindTexture(GL_TEXTURE_2D, this->texture);
+  /* not Working, and not needed. 
+  glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
+		height, 0, GL_BGR,
+		GL_UNSIGNED_BYTE, map->pixels );
+  */ 
+  gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->width, pImage->height, pImage->format, GL_UNSIGNED_BYTE, pImage->data);
+  
+  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
+  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);	
+}
+
+
+#ifdef HAVE_SDL_SDL_IMAGE_H
+bool Texture::loadImage(char* imageName)
+{
+  char* imgNameWithPath = searchTextureInPaths(imageName);
+  if (imgNameWithPath)
+    {
+      this->map=IMG_Load(imgNameWithPath);
+      if(!map)
+	{
+	  PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
+	  return false;
+	}
+      pImage->height = map->h;
+      pImage->width  = map->w;
+      pImage->data   = (GLubyte*)map->pixels;
+      pImage->bpp    = map->format->BytesPerPixel;
+      if (pImage->bpp == 3)
+	pImage->format = GL_RGB;
+      else if (pImage->bpp == 4)
+	pImage->format = GL_RGBA;
+	  
+      PRINTF(0)("Bits Per Pixel: %d\n", pImage->bpp);
+      if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))
+	for (int i=0;i<map->h * map->w *3;i+=3)
+	  { 
+	    GLuint temp = pImage->data[i];
+	    pImage->data[i] = pImage->data[i+2];
+	    pImage->data[i+2] = temp;
+	  }
+      /* this is the real swapping algorithm */
+      for( int i = 0 ; i < (pImage->height / 2) ; ++i )
+	for( int j = 0 ; j < pImage->width * pImage->bpp; j += pImage->bpp )
+	  for(int k = 0; k < pImage->bpp; ++k)
+	    swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]);
+ 
+      this->loadTexToGL (this->pImage);
+      SDL_FreeSurface(map);
+      this->pImage->data = NULL;
+    }
+  else
+    {
+      PRINTF(1)("Image not Found: %s\n", imgNameWithPath);
+      return false;
+    }
+}
+
+
+#else /* HAVE_SDL_SDL_IMAGE_H */
+/**
+   \brief Makes the Programm ready to Read-in a texture-File
+   1. Checks what type of Image should be imported
+   2. ToDO: Checks where to find the Image
+*/
+bool Texture::loadImage(char* imageName)
+{
+  char* imgNameWithPath = searchTextureInPaths(imageName);
+  if (imgNameWithPath)
+    {
+      if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".bmp", 4))
+	{
+	  PRINTF(3)("Requested bmp-image. Trying to Import.\n");
+	  return this->loadBMP(imgNameWithPath);
+	}
+      
+      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".jpg", 4) || !strncmp(imgNameWithPath+strlen(imgNameWithPath)-5, ".jpg", 5))
+	{
+	  PRINTF(3)("Requested jpeg-image. Trying to Import\n");
+	  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);
+	}
+      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
+	{
+	  PRINTF(3)("Requested png-image. Trying to Import\n");
+	  return this->loadPNG(imgNameWithPath);
+	}
+      else
+	{
+	  PRINTF(1)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", imgNameWithPath);
+	  return false;
+	}
+    }
+  else
+    {
+      PRINTF(1)("Image not Found: %s\n", imgNameWithPath);
+      return false;
+    }
+}
+
+/**
+   \brief reads in a Windows BMP-file, and imports it to openGL.
+   \param bmpName The name of the Image to load.
+   \param texture A pointer to the Texture which should be read to.
+*/
+bool Texture::loadBMP (char* bmpName)
+{
+  FILE *file;
+  unsigned long size;                 // size of the image in bytes.
+  unsigned long i;                    // standard counter.
+  unsigned short int planes;          // number of planes in image (must be 1) 
+  unsigned short int bpp;             // number of bits per pixel (must be 24)
+  GLuint temp;                          // temporary color storage for bgr-rgb conversion.
+
+  // make sure the file is there.
+  if ((file = fopen(bmpName, "rb"))==NULL)
+    {
+      PRINTF(1)("File Not Found : %s\n",bmpName);
+      return false;
+    }
+  // seek through the bmp header, up to the width/height:
+  fseek(file, 18, SEEK_CUR);
+  
+  // read the width
+  if ((i = fread(&pImage->width, 4, 1, file)) != 1) 
+    {
+      PRINTF(1)("Error reading width from %s.\n", bmpName);
+      return false;
+    }
+  // read the height 
+  if ((i = fread(&pImage->height, 4, 1, file)) != 1) 
+    {
+      PRINTF(1)("Error reading height from %s.\n", bmpName);
+      return false;
+    }
+  
+  // calculate the size (assuming 24 bits or 3 bytes per pixel).
+  size = pImage->width * pImage->height * 3;
+  
+  // read the planes
+  if ((fread(&planes, 2, 1, file)) != 1) 
+    {
+      PRINTF(1)("Error reading planes from %s.\n", bmpName);
+      return false;
+    }
+  if (planes != 1) 
+    {
+      PRINTF(1)("Planes from %s is not 1: %u\n", bmpName, planes);
+      return false;
+    }
+  
+  // read the bpp
+  if ((i = fread(&bpp, 2, 1, file)) != 1) 
+    {
+      PRINTF(1)("Error reading bpp from %s.\n", bmpName);
+      return false;
+    }
+  if (bpp != 24) 
+    {
+      PRINTF(1)("Bpp from %s is not 24: %u\n", bmpName, bpp);
+      return false;
+    }
+  
+  // seek past the rest of the bitmap header.
+  fseek(file, 24, SEEK_CUR);
+  
+  // read the data. 
+  pImage->data = (GLubyte *) malloc(size);
+  if (pImage->data == NULL) 
+    {
+      PRINTF(1)("Error allocating memory for color-corrected image data");
+      return false;	
+    }
+  
+  if ((i = fread(pImage->data, size, 1, file)) != 1) 
+    {
+      PRINTF(1)("Error reading image data from %s.\n", bmpName);
+      return false;
+    }
+  fclose(file);
+
+  // reverse all of the colors. (bgr -> rgb)
+  for (i=0;i<size;i+=3) 
+    { 
+      temp = pImage->data[i];
+      pImage->data[i] = pImage->data[i+2];
+      pImage->data[i+2] = temp;
+    }
+  this->loadTexToGL (pImage);
+  
+
+  if (pImage)
+    {
+      if (pImage->data)
+	{
+	  free(pImage->data);
+	}
+      
+      free(pImage);
+    }
+  return true;
+
+}
+
+/**
+   \brief reads in a jpg-file
+   \param jpgName the Name of the Image to load
+   \param texture a reference to the Texture to write the image to
+*/
+bool Texture::loadJPG (char* jpgName)
+{
+#ifdef HAVE_JPEGLIB_H
+  struct jpeg_decompress_struct cinfo;
+  Image *pImage = NULL;
+  FILE *pFile;
+  
+  // Open a file pointer to the jpeg file and check if it was found and opened 
+  if((pFile = fopen(jpgName, "rb")) == NULL) 
+    {
+      // Display an error message saying the file was not found, then return NULL
+      PRINTF(1)("Unable to load JPG File %s.\n", jpgName);
+      return false;
+    }
+  
+  // Create an error handler
+  jpeg_error_mgr jerr;
+  
+  // Have our compression info object point to the error handler address
+  cinfo.err = jpeg_std_error(&jerr);
+  
+  // Initialize the decompression object
+  jpeg_create_decompress(&cinfo);
+  
+  // Specify the data source (Our file pointer)	
+  jpeg_stdio_src(&cinfo, pFile);
+  
+  // Allocate the structure that will hold our eventual jpeg data (must free it!)
+  pImage = (Image*)malloc(sizeof(Image));
+  
+  // DECOFING
+  // Read in the header of the jpeg file
+  jpeg_read_header(&cinfo, TRUE);
+  
+  // Start to decompress the jpeg file with our compression info
+  jpeg_start_decompress(&cinfo);
+  
+  // Get the image dimensions and row span to read in the pixel data
+  pImage->rowSpan = cinfo.image_width * cinfo.num_components;
+  pImage->width   = cinfo.image_width;
+  pImage->height   = cinfo.image_height;
+  
+  // Allocate memory for the pixel buffer
+  pImage->data = new unsigned char[pImage->rowSpan * pImage->height];
+  
+  // Here we use the library's state variable cinfo.output_scanline as the
+  // loop counter, so that we don't have to keep track ourselves.
+  
+  // Create an array of row pointers
+  unsigned char** rowPtr = new unsigned char*[pImage->height];
+  for (int i = 0; i < pImage->height; i++)
+    rowPtr[i] = &(pImage->data[i*pImage->rowSpan]);
+  
+  // Now comes the juice of our work, here we extract all the pixel data
+  int rowsRead = 0;
+  while (cinfo.output_scanline < cinfo.output_height) 
+    {
+      // Read in the current row of pixels and increase the rowsRead count
+      rowsRead += jpeg_read_scanlines(&cinfo, &rowPtr[rowsRead], cinfo.output_height - rowsRead);
+    }
+  
+  // Delete the temporary row pointers
+  delete [] rowPtr;
+  
+  // Finish decompressing the data
+  jpeg_finish_decompress(&cinfo);//  decodeJPG(&cinfo, pImage);
+  
+  // This releases all the stored memory for reading and decoding the jpeg
+  jpeg_destroy_decompress(&cinfo);
+  
+  // Close the file pointer that opened the file
+  fclose(pFile);
+  
+
+  if(pImage == NULL)
+    exit(0);
+  
+  this->loadTexToGL (pImage);
+  if (pImage)
+    {
+      if (pImage->data)
+	{
+	  free(pImage->data);
+	}
+      
+      free(pImage);
+    }
+  return true;
+#else /* HAVE_JPEGLIB_H */
+  PRINTF(1)("sorry, but you did not compile with jpeg-support.\nEither install SDL_image or jpeglib, and recompile to see the image\n");
+  return false;
+#endif /* HAVE_JPEGLIB_H */
+
+}
+
+/**
+   \brief reads in a tga-file
+   \param tgaName the Name of the Image to load
+   \param texture a reference to the Texture to write the image to
+*/
+bool Texture::loadTGA(const char * tgaName)
+{
+  typedef struct
+  {
+    GLubyte Header[12];
+  } TGAHeader;
+  TGAHeader tgaHeader;			
+  
+  GLubyte uTGAcompare[12] = {0,0,2, 0,0,0,0,0,0,0,0,0};	// Uncompressed TGA Header 
+  GLubyte cTGAcompare[12] = {0,0,10,0,0,0,0,0,0,0,0,0};	// Compressed TGA Header 
+  FILE * fTGA;
+  fTGA = fopen(tgaName, "rb");
+
+  if(fTGA == NULL)
+    {
+      PRINTF(1)("Error could not open texture file: %s\n", tgaName);
+      return false;
+    }
+  
+  if(fread(&tgaHeader, sizeof(TGAHeader), 1, fTGA) == 0)
+    {
+      PRINTF(1)("Error could not read file header of %s\n", tgaName);
+      if(fTGA != NULL)
+	{
+	  fclose(fTGA);
+	}
+      return false;
+    }
+  
+  if(memcmp(uTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
+    {
+      loadUncompressedTGA(tgaName, fTGA);
+      if (fTGA)
+	fclose (fTGA);
+    }
+  else if(memcmp(cTGAcompare, &tgaHeader, sizeof(TGAHeader)) == 0)
+    {
+      loadCompressedTGA(tgaName, fTGA);
+	if (fTGA)
+	  fclose (fTGA);
+    }
+  else
+    {
+      PRINTF(1)("Error TGA file be type 2 or type 10\n");
+      if (fTGA)
+	fclose(fTGA);
+      return false;
+    }
+  return true;
+}
+
+/**
+   \brief reads in an uncompressed tga-file
+   \param filename the Name of the Image to load
+   \param fTGA a Pointer to a File, that should be read
+   \param texture a reference to the Texture to write the image to
+*/
+bool Texture::loadUncompressedTGA(const char * filename, FILE * fTGA)
+{
+  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 
+
+  GLuint cswap;
+  if(fread(header, sizeof(header), 1, fTGA) == 0)
+    {
+      PRINTF(1)("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];
+  // Make sure all information is valid
+  if((pImage->width <= 0) || (pImage->height <= 0) || ((pImage->bpp != 24) && (pImage->bpp !=32)))
+    {
+      PRINTF(1)("Error invalid texture information\n");
+      return false;
+    }
+  
+  if(pImage->bpp == 24)	
+    {
+      pImage->type = GL_RGB;
+    }
+  else
+    {
+      pImage->type = GL_RGBA;
+    }
+  
+  bytesPerPixel	= (Bpp / 8);
+  imageSize = (bytesPerPixel * Width * Height);
+  pImage->data = (GLubyte*) malloc(imageSize);
+  
+  if(pImage->data == NULL)
+    {
+      PRINTF(1)("Error could not allocate memory for image\n");
+      return false;
+    }
+  
+  if(fread(pImage->data, 1, imageSize, fTGA) != imageSize)
+    {
+      PRINTF(1)("Error could not read image data\n");
+      if(pImage->data != NULL)
+	{
+	  free(pImage->data);
+	}
+      return false;
+    }
+  
+  for(cswap = 0; cswap < (int)imageSize; cswap += bytesPerPixel)
+    {
+      pImage->data[cswap] ^= pImage->data[cswap+2] ^=
+	pImage->data[cswap] ^= pImage->data[cswap+2];
+    }
+  
+  this->loadTexToGL (pImage);
+
+  return true;
+}
+
+/**
+   \brief reads in a compressed tga-file
+   \param filename the Name of the Image to load
+   \param fTGA a Pointer to a File, that should be read
+   \param texture a reference to the Texture to write the image to
+*/
+bool Texture::loadCompressedTGA(const char * filename, FILE * fTGA)
+{
+  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 
+
+  if(fread(header, sizeof(header), 1, fTGA) == 0)
+    {
+      PRINTF(1)("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(1)("Error Invalid pImage information\n");
+      return false;
+    }
+  
+  bytesPerPixel	= (Bpp / 8);
+  imageSize		= (bytesPerPixel * Width * Height);
+  pImage->data	= (GLubyte*) malloc(imageSize);
+  
+  if(pImage->data == NULL)
+    {
+      PRINTF(1)("Error could not allocate memory for image\n");
+      return false;
+    }
+  
+  do
+    {
+      GLubyte chunkheader = 0;
+      
+      if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
+	{
+	  PRINTF(1)("Error could not read RLE header\n");
+	  if(pImage->data != NULL)
+	    {
+	      free(pImage->data);
+	    }
+	  return false;
+	}
+      // If the ehader is < 128, it means the that is the number of RAW color packets minus 1 
+      if(chunkheader < 128)
+	{
+	  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(1)("Error could not read image data\n");
+		  if(colorbuffer != NULL)
+		    {
+		      free(colorbuffer);
+		    }
+		  
+		  if(pImage->data != NULL)
+		    {
+		      free(pImage->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(1)("Error too many pixels read\n");
+		  if(colorbuffer != NULL)
+		    {
+		      free(colorbuffer);
+		    }
+		  
+		  if(pImage->data != NULL)
+		    {
+		      free(pImage->data);
+		    }
+		  
+		  return false;
+		}
+	    }
+	}
+      // 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 
+	    {
+	      PRINTF(1)("Error could not read from file");
+	      if(colorbuffer != NULL)
+		{
+		  free(colorbuffer);
+		}
+	      
+	      if(pImage->data != NULL)
+		{
+		  free(pImage->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
+	      pImage->data[currentbyte	  ] = colorbuffer[2];
+	      pImage->data[currentbyte + 1] = colorbuffer[1];
+	      pImage->data[currentbyte + 2] = colorbuffer[0];
+	      
+	      if(bytesPerPixel == 4)
+		{
+		  pImage->data[currentbyte + 3] = colorbuffer[3];
+		}
+	      
+	      currentbyte += bytesPerPixel;
+	      currentpixel++;
+	      
+	      if(currentpixel > pixelcount)
+		{
+		  PRINTF(1)("Error too many pixels read\n");
+		  if(colorbuffer != NULL)
+		    {
+		      free(colorbuffer);
+		    }
+		  
+		  if(pImage->data != NULL)
+		    {
+		      free(pImage->data);
+		    }
+		  
+		  return false;
+		}
+	    }
+	}
+    }
+  
+  while(currentpixel < pixelcount);	// Loop while there are still pixels left
+
+  this->loadTexToGL (pImage);
+
+  return true;
+}
+
+
+/*
+static int ST_is_power_of_two(unsigned int number)
+{
+  return (number & (number - 1)) == 0;
+}
+*/
+
+/**
+   \brief reads in a png-file
+   \param pngName the Name of the Image to load
+   \param texture a reference to the Texture to write the image to
+*/
+bool Texture::loadPNG(const char* pngName)
+{
+#ifdef HAVE_PNG_H
+
+  FILE *PNG_file = fopen(pngName, "rb");
+  if (PNG_file == NULL)
+    {
+      return 0;
+    }
+  
+  GLubyte PNG_header[8];
+  
+  fread(PNG_header, 1, 8, PNG_file);
+  if (png_sig_cmp(PNG_header, 0, 8) != 0)
+    {
+      PRINTF(2)("Not Recognized as a pngFile\n");
+      fclose (PNG_file);
+      return 0;
+    }
+  
+  png_structp PNG_reader = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+  if (PNG_reader == NULL)
+    {
+      fclose(PNG_file);
+      return 0;
+    }
+  
+  png_infop PNG_info = png_create_info_struct(PNG_reader);
+  if (PNG_info == NULL)
+    {
+      png_destroy_read_struct(&PNG_reader, NULL, NULL);
+      fclose(PNG_file);
+      return 0;
+    }
+  
+  png_infop PNG_end_info = png_create_info_struct(PNG_reader);
+  if (PNG_end_info == NULL)
+    {
+      png_destroy_read_struct(&PNG_reader, &PNG_info, NULL);
+      fclose(PNG_file);
+      return 0;
+    }
+  
+  if (setjmp(png_jmpbuf(PNG_reader)))
+    {
+      png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
+      fclose(PNG_file);
+      return (0);
+    }
+  
+  png_init_io(PNG_reader, PNG_file);
+  png_set_sig_bytes(PNG_reader, 8);
+  
+  png_read_info(PNG_reader, PNG_info);
+  
+  pImage->width = png_get_image_width(PNG_reader, PNG_info);
+  pImage->height = png_get_image_height(PNG_reader, PNG_info);
+  
+  png_uint_32 bit_depth, color_type;
+  bit_depth = png_get_bit_depth(PNG_reader, PNG_info);
+  color_type = png_get_color_type(PNG_reader, PNG_info);
+  
+  if (color_type == PNG_COLOR_TYPE_PALETTE)
+    {
+      png_set_palette_to_rgb(PNG_reader);
+    }
+  
+  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
+    {
+      png_set_gray_1_2_4_to_8(PNG_reader);
+    }
+  
+  if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+    {
+      png_set_gray_to_rgb(PNG_reader);
+    }
+  
+  if (png_get_valid(PNG_reader, PNG_info, PNG_INFO_tRNS))
+    {
+      png_set_tRNS_to_alpha(PNG_reader);
+    }
+  else
+    {
+      png_set_filler(PNG_reader, 0xff, PNG_FILLER_AFTER);
+    }
+  
+  if (bit_depth == 16)
+    {
+      png_set_strip_16(PNG_reader);
+    }
+  
+  png_read_update_info(PNG_reader, PNG_info);
+  
+  pImage->data = (png_byte*)malloc(4 * pImage->width * pImage->height);
+  png_byte** PNG_rows = (png_byte**)malloc(pImage->height * sizeof(png_byte*));
+  
+  unsigned int row;
+  for (row = 0; row < pImage->height; ++row)
+    {
+      PNG_rows[pImage->height - 1 - row] = pImage->data + (row * 4 * pImage->width);
+    }
+  
+  png_read_image(PNG_reader, PNG_rows);
+  
+  free(PNG_rows);
+  
+  png_destroy_read_struct(&PNG_reader, &PNG_info, &PNG_end_info);
+  fclose(PNG_file);
+  
+  /*  if (!ST_is_power_of_two(pImage->width) || !ST_is_power_of_two(pImage->height))
+    {
+      free(pImage->data);
+      return 0;
+    }
+  */
+  this->loadTexToGL (pImage);  
+  
+  free(pImage->data);
+  
+  return true;
+#else /* HAVE_PNG_H */
+  PRINTF(1)("sorry, but you did not compile with png-support.\nEither install SDL_image or libpng, and recompile to see the image\n");
+  return false;
+#endif /* HAVE_PNG_H */
+
+}
+#endif /* HAVE_SDL_SDL_IMAGE_H */
Index: orxonox/trunk/src/importer/texture.h
===================================================================
--- orxonox/trunk/src/importer/texture.h	(revision 3365)
+++ orxonox/trunk/src/importer/texture.h	(revision 3365)
@@ -0,0 +1,100 @@
+/*!
+  \file texture.h
+  \brief Contains the texture class, that handles the reading of Images into Texutre-files.
+
+  \todo free SDL-surface when deleting Material.
+  \todo delete imgNameWithPath after use creation.
+*/
+
+#ifndef _TEXTURE_H
+#define _TEXTURE_H
+
+#include "../stdincl.h"
+extern int verbose;
+#ifdef HAVE_SDL_SDL_IMAGE_H
+#include <SDL/SDL_image.h>
+#else
+// IMAGE LIBS //
+#ifdef HAVE_JPEGLIB_H
+extern "C"{         // This has to be done, because not a c++ lib
+#include <jpeglib.h>
+}
+#endif /* HAVE_JPEGLIB_H */
+#ifdef HAVE_PNG_H
+#include <png.h>
+#endif /* HAVE_PNG_H */
+#endif /* HAVE_SDL_SDL_IMAGE_H */
+
+
+
+//! Class to handle lists of paths.
+/**
+   \todo Ability to return Paths by itself.
+
+   It is simple to use, and good, for all PathList you want.
+   just create a new Pathlist, and add Paths.
+*/
+class PathList
+{
+ private:
+  PathList();
+  static PathList* firstPath; //!< A static Pointer to the first PathList in the List.
+ public:
+  PathList(char* pName);
+  ~PathList();
+  static PathList* getInstance(void);
+  
+  void addPath (char* pName);
+  char* pathName;              //!< The Name of the current Path.
+  PathList* next;              //!< Pointer to the next Pathlist.
+};
+
+//! A Class, that reads in Textures from different fileformats.
+class Texture
+{
+ private:
+  //! Struct to handle Infos about an Image
+  struct Image
+  {
+    int rowSpan;    //!< The count of the rows this Image has.
+    GLuint width;   //!< The width of the Image.
+    GLuint height;  //!< The height of the Image.
+    GLuint bpp;     //!< BytesPerPixel
+    GLenum format;  //!< The Format of the PixelData
+    GLuint type;    //!< Type of the Image.
+    GLubyte *data;  //!< The Image Data comes here! DANGER: uncompressed data.
+  };
+  Image* pImage;
+  GLuint texture;
+  SDL_Surface* map;
+  char* searchTextureInPaths(char* texName) const;
+  inline void swap(unsigned char &a, unsigned char &b);
+ public:
+  Texture(void);
+  ~Texture(void);
+
+  inline GLuint getTexture(void) {return this->texture;} //!< \returns The textureID of this texture.
+  bool loadTexToGL (Image* pImage);
+
+  bool loadImage(char* imageName);
+#ifndef HAVE_SDL_SDL_IMAGE_H
+
+  bool loadBMP (char* bmpName);
+
+  bool loadJPG (char* jpgName);
+
+  /// TGA ///
+
+  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);
+#endif
+
+
+};
+
+
+
+#endif /* _TEXTURE_H */
