Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 1, 2006, 9:08:19 PM (18 years ago)
Author:
bottac
Message:

Experimental lightmapping. Screenshots: http://people.ee.ethz.ch/~bottac/lightmap_test/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.cc

    r7410 r7465  
    181181    bspFile.read((char*)this->faces, size);
    182182
     183    //Get the lightmaps
     184    offset = SDL_SwapLE32(((int *)(header))[30]);
     185    size    = SDL_SwapLE32(((int *)(header))[31]);
     186    this->numLightMaps = size/ sizeof(lightmap);
     187    this->lightMaps = new lightmap [this->numLightMaps];
     188    bspFile.seekg(offset);
     189    bspFile.read((char*)this->lightMaps, size);
     190
     191
    183192    // Get the Visdata
    184193    offset = SDL_SwapLE32(((int *)(header))[34]);
     
    213222      PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]);
    214223    this->load_textures();
     224   
     225    // Load the lightMaps
     226    this->glLightMapTextures = new GLuint[this->numLightMaps];
     227    for(int i = 0; i < this->numLightMaps; i++)
     228      this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]);
     229   
     230    //Create white texture for if no lightmap specified
     231    glGenTextures(1, &this->whiteLightMap);
     232    glBindTexture(GL_TEXTURE_2D, this->whiteLightMap);
     233        //Create texture
     234    this->whiteTexture[0]=255;
     235    this->whiteTexture[1]=255;
     236    this->whiteTexture[2]=255;
     237   
     238    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     239    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
     240    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
     241    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     242
     243    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
     244
     245
     246 
     247    /* control the mipmap levels */
     248    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     249    glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
     250
     251    /* build the Texture  OpenGL V >= 1.1 */
     252    glTexImage2D(GL_TEXTURE_2D,
     253                 0,
     254                 GL_RGBA8,
     255                 1,
     256                 1,
     257                 0,
     258                 GL_RGB,
     259                 GL_UNSIGNED_BYTE,
     260                 (const GLvoid *)&(this->whiteTexture));
     261
     262    gluBuild2DMipmaps(  GL_TEXTURE_2D, GL_RGBA8, 1, 1,
     263                       GL_RGB, GL_FLOAT,(const GLvoid *) &(this->whiteTexture));
     264   
     265   
    215266
    216267    // Get the number of patches
     
    413464      PRINTF(0)("BSP FILE: gefunden . \n");
    414465      this->Materials[i] =this->loadMat(fileName);
    415       continue;
     466     
    416467    }
    417468
     
    471522}
    472523
     524unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture)
     525{
     526  int      errorCode = 0;           //!< the error code for the texture loading functions
     527  unsigned int   lightMap;                 //!< the OpenGL texture handle
     528  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
     529  int      mipmapWidth = 0;         //!< the width of the mipmap
     530  int      mipmapHight = 0;         //!< the height of the mipmap
     531
     532  float sc, scale, temp;
     533  for(int i = 0; i < 128*128*3 ; i++)
     534  {
     535  sc =  ((unsigned char *)(&lightMapTexture))[i];
     536  sc *= 10.5/255.0;
     537  scale = 1.0;
     538  if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp;
     539  scale*=255.0;
     540  sc*=scale;
     541    ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc;
     542   
     543 
     544  }
     545 
     546  glGenTextures(1, &lightMap);
     547  glBindTexture(GL_TEXTURE_2D,  lightMap);
     548  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     549  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
     550  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
     551  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     552
     553  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2);
     554
     555
     556  /* control the mipmap levels */
     557  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);
     558  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
     559
     560  /* build the Texture  OpenGL V >= 1.1 */
     561   glTexImage2D(GL_TEXTURE_2D,
     562                   0,
     563                   GL_RGBA8,
     564                   128,
     565                   128,
     566                   0,
     567                   GL_RGB,
     568                   GL_UNSIGNED_BYTE,
     569                   (const GLvoid *)&lightMapTexture);
     570
     571   
     572   // build the MipMaps automaticaly
     573   errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
     574GL_RGBA8,
     575                                 128,
     576                                 128,
     577                                 GL_RGB,
     578                                 GL_UNSIGNED_BYTE,
     579                                 (const GLvoid *)&lightMapTexture
     580                                );
     581   
     582
     583
     584
     585  return lightMap;
     586
     587}
     588
    473589void BspFile::tesselate(int iface)
    474590{
     
    784900  // Overwrite Face->meshvert;
    785901  // Overwrite Face->n_meshverts;
    786   int sz = (Face->size[0] -1)/2 * (Face->size[1] -1)/2; // num patches
     902  int sz = (size0 -1)/2 * (size1 -1)/2; // num patches
    787903  Face->meshvert = patchOffset -sz;  //3*(patchOffset-sz)*level1*level1;
    788904  Face->n_meshverts = sz;
Note: See TracChangeset for help on using the changeset viewer.