Index: branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7410)
+++ branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7465)
@@ -181,4 +181,13 @@
     bspFile.read((char*)this->faces, size);
 
+    //Get the lightmaps
+    offset = SDL_SwapLE32(((int *)(header))[30]);
+    size    = SDL_SwapLE32(((int *)(header))[31]);
+    this->numLightMaps = size/ sizeof(lightmap);
+    this->lightMaps = new lightmap [this->numLightMaps];
+    bspFile.seekg(offset);
+    bspFile.read((char*)this->lightMaps, size);
+
+
     // Get the Visdata
     offset = SDL_SwapLE32(((int *)(header))[34]);
@@ -213,4 +222,46 @@
       PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]);
     this->load_textures();
+    
+    // Load the lightMaps
+    this->glLightMapTextures = new GLuint[this->numLightMaps];
+    for(int i = 0; i < this->numLightMaps; i++)
+      this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]);
+    
+    //Create white texture for if no lightmap specified
+    glGenTextures(1, &this->whiteLightMap);
+    glBindTexture(GL_TEXTURE_2D, this->whiteLightMap);
+	//Create texture
+    this->whiteTexture[0]=255;
+    this->whiteTexture[1]=255;
+    this->whiteTexture[2]=255;
+    
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
+
+
+  
+    /* control the mipmap levels */
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
+    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+
+    /* build the Texture  OpenGL V >= 1.1 */
+    glTexImage2D(GL_TEXTURE_2D,
+                 0,
+                 GL_RGBA8,
+                 1,
+                 1,
+                 0,
+                 GL_RGB,
+                 GL_UNSIGNED_BYTE,
+                 (const GLvoid *)&(this->whiteTexture));
+
+    gluBuild2DMipmaps(	GL_TEXTURE_2D, GL_RGBA8, 1, 1,
+                       GL_RGB, GL_FLOAT,(const GLvoid *) &(this->whiteTexture));
+    
+    
 
     // Get the number of patches
@@ -413,5 +464,5 @@
       PRINTF(0)("BSP FILE: gefunden . \n");
       this->Materials[i] =this->loadMat(fileName);
-      continue;
+      
     }
 
@@ -471,4 +522,69 @@
 }
 
+unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture)
+{
+  int      errorCode = 0;           //!< the error code for the texture loading functions
+  unsigned int   lightMap;                 //!< the OpenGL texture handle
+  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
+  int      mipmapWidth = 0;         //!< the width of the mipmap
+  int      mipmapHight = 0;         //!< the height of the mipmap
+
+  float sc, scale, temp;
+  for(int i = 0; i < 128*128*3 ; i++)
+  {
+  sc =  ((unsigned char *)(&lightMapTexture))[i];
+  sc *= 10.5/255.0;
+  scale = 1.0;
+  if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp;
+  scale*=255.0;
+  sc*=scale;
+    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc; 
+    
+  
+  }
+  
+  glGenTextures(1, &lightMap);
+  glBindTexture(GL_TEXTURE_2D,  lightMap);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
+
+
+  /* control the mipmap levels */
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
+  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
+
+  /* build the Texture  OpenGL V >= 1.1 */
+   glTexImage2D(GL_TEXTURE_2D,
+                   0,
+                   GL_RGBA8,
+                   128,
+                   128,
+                   0,
+                   GL_RGB,
+                   GL_UNSIGNED_BYTE,
+                   (const GLvoid *)&lightMapTexture);
+
+   
+   // build the MipMaps automaticaly
+   errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
+GL_RGBA8,
+                                 128,
+                                 128,
+                                 GL_RGB,
+                                 GL_UNSIGNED_BYTE,
+                                 (const GLvoid *)&lightMapTexture
+                                );
+   
+
+
+
+  return lightMap;
+
+}
+
 void BspFile::tesselate(int iface)
 {
@@ -784,5 +900,5 @@
   // Overwrite Face->meshvert;
   // Overwrite Face->n_meshverts;
-  int sz = (Face->size[0] -1)/2 * (Face->size[1] -1)/2; // num patches
+  int sz = (size0 -1)/2 * (size1 -1)/2; // num patches
   Face->meshvert = patchOffset -sz;  //3*(patchOffset-sz)*level1*level1;
   Face->n_meshverts = sz;
