Index: /branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_file.cc	(revision 7464)
+++ /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;
Index: /branches/bsp_model/src/lib/graphics/importer/bsp_file.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7464)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_file.h	(revision 7465)
@@ -88,5 +88,5 @@
   int lm_index;         //!< Lightmap index.
   int lm_start [ 2 ];   //!< Corner of this face's lightmap image in lightmap.
-  int lm_size[ 2 ];     //!< Size of this face's lightmap image in lightmap.
+  int lm_size [ 2 ];     //!< Size of this face's lightmap image in lightmap.
   float lm_origin [ 3 ] ;    //!<  World space origin of lightmap.
   float lm_vecs [ 2 ][ 3 ];  //!< World space lightmap s and t unit vectors.
@@ -123,4 +123,10 @@
 AMat;
 
+typedef struct
+{
+  unsigned char map [128][128][3];
+}
+lightmap;
+
 class BspFile
 {
@@ -153,9 +159,10 @@
   char* visData;             //!<
   char* textures;            //!<
-  char* patchVertice;
+  char* patchVertice;        //!<
   char* patchIndexes;
   char* patchTrianglesPerRow;
-  
-  
+  lightmap* lightMaps;       //!< Buffer to store lightmap-images
+
+
   int** patchRowIndexes;
   VertexArrayModel** VertexArrayModels;
@@ -173,7 +180,12 @@
   int numPatches;
   int numBrushSides;
+  int numLightMaps;
 
   BspTreeNode* build_tree_rec( int i );
+  unsigned int loadLightMapToGL(lightmap&);
   AMat* Materials;
+  unsigned int* glLightMapTextures;
+  unsigned int whiteLightMap;
+  unsigned char whiteTexture[3];
   SDL_Surface* testSurf;
 
Index: /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7464)
+++ /branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc	(revision 7465)
@@ -87,9 +87,9 @@
   this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
 
-  if ((((int *)(this->bspFile->header))[35] == 0)  || viscluster < 0)  //!< if (sizeof(Visdata) == 0)
+  if (true /*(((int *)(this->bspFile->header))[35] == 0 )  || viscluster < 0*/)  //!< if (sizeof(Visdata) == 0)
   {
     /** Do Frustum culling and draw 'em all **/
 
-    // Iterate through all Leafs
+    // Iterate through all Leafspublic final double readLEDouble()
     for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
     {
@@ -103,5 +103,5 @@
         if (f >=0 && !this->isAlreadyVisible(f)) {
           this->alreadyVisible[f] = true;
-          /*	if(ActLeaf->leafIndex == i)
+          /*	if(ActLeaf->leafIndex == i)public final double readLEDouble()
           	{
           		this->alreadyVisible[i] = false;
@@ -190,10 +190,25 @@
   if(curFace.type == 3) return;
   // if(this->bspFile->Materials[curFace.texture] != NULL)
-  if(this->lastTex != curFace.texture) {
-    this->bspFile->Materials[curFace.texture].mat->select();
-    this->lastTex = curFace.texture;
-  }
+  //if(this->lastTex != curFace.texture) {
+    this->bspFile->Materials[curFace.texture].mat->select0();
+  //   this->lastTex = curFace.texture;
+  //}
+    
+    if(curFace.lm_index < 0) 
+    {
+      glActiveTextureARB(GL_TEXTURE1_ARB);
+      glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
+      glEnable(GL_TEXTURE_2D);
+    }
+    else
+    {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
+    glEnable(GL_TEXTURE_2D);
+    }
+    
+    glColor4f(3.0,3.0,3.0,0.9);
   glEnableClientState(GL_VERTEX_ARRAY );
-  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+  //glEnableClientState(GL_TEXTURE_COORD_ARRAY );
   glEnableClientState(GL_NORMAL_ARRAY );
   //  glEnableClientState(GL_COLOR_ARRAY);
@@ -201,10 +216,14 @@
 
   glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
-  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  
+  glClientActiveTextureARB(GL_TEXTURE0_ARB);
   glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
-  // glClientActiveTextureARB(GL_TEXTURE1_ARB);
-  // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
-
-
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+  
+  glClientActiveTextureARB(GL_TEXTURE1_ARB);
+  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+  
   glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
   // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
@@ -212,7 +231,8 @@
                  GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
 
-
+  glDisableClientState(GL_TEXTURE0_ARB);
+  glDisableClientState(GL_TEXTURE1_ARB);
   glDisableClientState(GL_VERTEX_ARRAY );
-  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
+  //glDisableClientState(GL_TEXTURE_COORD_ARRAY );
   glDisableClientState(GL_NORMAL_ARRAY );
   // glDisableClientState(GL_COLOR_ARRAY);
@@ -247,8 +267,11 @@
   //glEnableClientState(GL_COLOR_ARRAY);
   // glEnableClientState(GL_VERTEX_ARRAY );
-
+  glClientActiveTextureARB(GL_TEXTURE0_ARB);
   glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   // glClientActiveTextureARB(GL_TEXTURE0_ARB);
+  glClientActiveTextureARB(GL_TEXTURE1_ARB);
   glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   // glClientActiveTextureARB(GL_TEXTURE1_ARB);
   // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
@@ -265,17 +288,47 @@
 {
   if(this->lastTex != Face->texture) {
-    this->bspFile->Materials[Face->texture].mat->select();
+    this->bspFile->Materials[Face->texture].mat->select0();
     this->lastTex = Face->texture;
   }
-
+  
+  
+  
+  if(Face->lm_index < 0) 
+  {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
+    glEnable(GL_TEXTURE_2D);
+  }
+  else
+  {
+    glActiveTextureARB(GL_TEXTURE1_ARB);
+    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[Face->lm_index]);
+    glEnable(GL_TEXTURE_2D);
+}
+    glColor4f(3.0,3.0,3.0,0.9);
+  
+  glEnable( GL_AUTO_NORMAL);
+  glEnableClientState(GL_VERTEX_ARRAY );
+  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
   for(int i = 0; i < Face->n_meshverts  ; i++) {
-    //glFrontFace(GL_CW);
+    glFrontFace(GL_CW);
     //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
-    glEnableClientState(GL_VERTEX_ARRAY );
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY );
+  
+ 
     glEnableClientState(GL_NORMAL_ARRAY );
 
     glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
+    
+    
+    glClientActiveTextureARB(GL_TEXTURE0_ARB);
     glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+    
+    glClientActiveTextureARB(GL_TEXTURE1_ARB);
+    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0]));
+    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+    
     glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
 
@@ -291,8 +344,16 @@
                      & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
     }
-
-    //glFrontFace(GL_CCW);
-  }
-
+   
+    glFrontFace(GL_CCW);
+  }
+  glDisableClientState(GL_TEXTURE0_ARB);
+  glDisableClientState(GL_TEXTURE1_ARB);
+  glDisable(GL_AUTO_NORMAL);
+  glDisableClientState(GL_VERTEX_ARRAY );
+  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
+  
+  glBegin(GL_QUADS);
+  
+  glEnd();
 }
 
@@ -408,5 +469,5 @@
   glNormal3f( 1.0f, 0.0f, 0.0f);  glColor4f(0.2,0.2,0.9,.25);
 
-  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f, cam->z -1.0f);
+  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y -1.0f, cam->z -1.0f);
   glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
   glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z + 1.0f);
Index: /branches/bsp_model/src/lib/graphics/importer/material.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/material.cc	(revision 7464)
+++ /branches/bsp_model/src/lib/graphics/importer/material.cc	(revision 7465)
@@ -89,5 +89,12 @@
   this->setName(m.getName());
 }
-
+ 
+bool Material::select0() const
+{
+  glActiveTextureARB(GL_TEXTURE0_ARB);
+  glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
+  glEnable(GL_TEXTURE_2D); 
+  
+}
 
 /**
@@ -162,5 +169,5 @@
 /**
  *  Sets the Material Diffuse Color.
- * @param r Red Color Channel.
+ * @param r Red Color Channel.a
  * @param g Green Color Channel.
  * @param b Blue Color Channel.
Index: /branches/bsp_model/src/lib/graphics/importer/material.h
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/material.h	(revision 7464)
+++ /branches/bsp_model/src/lib/graphics/importer/material.h	(revision 7465)
@@ -32,5 +32,6 @@
 
   bool select () const;
-
+  bool select0 () const;
+      
   void setIllum (int illum);
   void setIllum (char* illum);
Index: /branches/bsp_model/src/lib/graphics/importer/texture.cc
===================================================================
--- /branches/bsp_model/src/lib/graphics/importer/texture.cc	(revision 7464)
+++ /branches/bsp_model/src/lib/graphics/importer/texture.cc	(revision 7465)
@@ -264,5 +264,5 @@
   glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
 
-  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/);
+  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
