Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7465 in orxonox.OLD for branches/bsp_model


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

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

Location:
branches/bsp_model/src/lib/graphics/importer
Files:
6 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;
  • branches/bsp_model/src/lib/graphics/importer/bsp_file.h

    r7410 r7465  
    8888  int lm_index;         //!< Lightmap index.
    8989  int lm_start [ 2 ];   //!< Corner of this face's lightmap image in lightmap.
    90   int lm_size[ 2 ];     //!< Size of this face's lightmap image in lightmap.
     90  int lm_size [ 2 ];     //!< Size of this face's lightmap image in lightmap.
    9191  float lm_origin [ 3 ] ;    //!<  World space origin of lightmap.
    9292  float lm_vecs [ 2 ][ 3 ];  //!< World space lightmap s and t unit vectors.
     
    123123AMat;
    124124
     125typedef struct
     126{
     127  unsigned char map [128][128][3];
     128}
     129lightmap;
     130
    125131class BspFile
    126132{
     
    153159  char* visData;             //!<
    154160  char* textures;            //!<
    155   char* patchVertice;
     161  char* patchVertice;        //!<
    156162  char* patchIndexes;
    157163  char* patchTrianglesPerRow;
    158  
    159  
     164  lightmap* lightMaps;       //!< Buffer to store lightmap-images
     165
     166
    160167  int** patchRowIndexes;
    161168  VertexArrayModel** VertexArrayModels;
     
    173180  int numPatches;
    174181  int numBrushSides;
     182  int numLightMaps;
    175183
    176184  BspTreeNode* build_tree_rec( int i );
     185  unsigned int loadLightMapToGL(lightmap&);
    177186  AMat* Materials;
     187  unsigned int* glLightMapTextures;
     188  unsigned int whiteLightMap;
     189  unsigned char whiteTexture[3];
    178190  SDL_Surface* testSurf;
    179191
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r7395 r7465  
    8787  this->checkCollision(this->root, &this->cam);   //!< Test Collision Detection
    8888
    89   if ((((int *)(this->bspFile->header))[35] == 0)  || viscluster < 0)  //!< if (sizeof(Visdata) == 0)
     89  if (true /*(((int *)(this->bspFile->header))[35] == 0 )  || viscluster < 0*/)  //!< if (sizeof(Visdata) == 0)
    9090  {
    9191    /** Do Frustum culling and draw 'em all **/
    9292
    93     // Iterate through all Leafs
     93    // Iterate through all Leafspublic final double readLEDouble()
    9494    for(int i = 0; i <  this->bspFile->numLeafs   ; i++ )
    9595    {
     
    103103        if (f >=0 && !this->isAlreadyVisible(f)) {
    104104          this->alreadyVisible[f] = true;
    105           /*    if(ActLeaf->leafIndex == i)
     105          /*    if(ActLeaf->leafIndex == i)public final double readLEDouble()
    106106                {
    107107                        this->alreadyVisible[i] = false;
     
    190190  if(curFace.type == 3) return;
    191191  // if(this->bspFile->Materials[curFace.texture] != NULL)
    192   if(this->lastTex != curFace.texture) {
    193     this->bspFile->Materials[curFace.texture].mat->select();
    194     this->lastTex = curFace.texture;
    195   }
     192  //if(this->lastTex != curFace.texture) {
     193    this->bspFile->Materials[curFace.texture].mat->select0();
     194  //   this->lastTex = curFace.texture;
     195  //}
     196   
     197    if(curFace.lm_index < 0)
     198    {
     199      glActiveTextureARB(GL_TEXTURE1_ARB);
     200      glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
     201      glEnable(GL_TEXTURE_2D);
     202    }
     203    else
     204    {
     205    glActiveTextureARB(GL_TEXTURE1_ARB);
     206    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]);
     207    glEnable(GL_TEXTURE_2D);
     208    }
     209   
     210    glColor4f(3.0,3.0,3.0,0.9);
    196211  glEnableClientState(GL_VERTEX_ARRAY );
    197   glEnableClientState(GL_TEXTURE_COORD_ARRAY );
     212  //glEnableClientState(GL_TEXTURE_COORD_ARRAY );
    198213  glEnableClientState(GL_NORMAL_ARRAY );
    199214  //  glEnableClientState(GL_COLOR_ARRAY);
     
    201216
    202217  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
    203   // glClientActiveTextureARB(GL_TEXTURE0_ARB);
     218 
     219  glClientActiveTextureARB(GL_TEXTURE0_ARB);
    204220  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
    205   // glClientActiveTextureARB(GL_TEXTURE1_ARB);
    206   // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
    207 
    208 
     221  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     222 
     223  glClientActiveTextureARB(GL_TEXTURE1_ARB);
     224  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
     225  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     226
     227 
    209228  glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0]));
    210229  // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0]));
     
    212231                 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert]));
    213232
    214 
     233  glDisableClientState(GL_TEXTURE0_ARB);
     234  glDisableClientState(GL_TEXTURE1_ARB);
    215235  glDisableClientState(GL_VERTEX_ARRAY );
    216   glDisableClientState(GL_TEXTURE_COORD_ARRAY );
     236  //glDisableClientState(GL_TEXTURE_COORD_ARRAY );
    217237  glDisableClientState(GL_NORMAL_ARRAY );
    218238  // glDisableClientState(GL_COLOR_ARRAY);
     
    247267  //glEnableClientState(GL_COLOR_ARRAY);
    248268  // glEnableClientState(GL_VERTEX_ARRAY );
    249 
     269  glClientActiveTextureARB(GL_TEXTURE0_ARB);
    250270  glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0]));
     271  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    251272  // glClientActiveTextureARB(GL_TEXTURE0_ARB);
     273  glClientActiveTextureARB(GL_TEXTURE1_ARB);
    252274  glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0]));
     275  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    253276  // glClientActiveTextureARB(GL_TEXTURE1_ARB);
    254277  // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1]));
     
    265288{
    266289  if(this->lastTex != Face->texture) {
    267     this->bspFile->Materials[Face->texture].mat->select();
     290    this->bspFile->Materials[Face->texture].mat->select0();
    268291    this->lastTex = Face->texture;
    269292  }
    270 
     293 
     294 
     295 
     296  if(Face->lm_index < 0)
     297  {
     298    glActiveTextureARB(GL_TEXTURE1_ARB);
     299    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[this->bspFile->whiteLightMap]);
     300    glEnable(GL_TEXTURE_2D);
     301  }
     302  else
     303  {
     304    glActiveTextureARB(GL_TEXTURE1_ARB);
     305    glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[Face->lm_index]);
     306    glEnable(GL_TEXTURE_2D);
     307}
     308    glColor4f(3.0,3.0,3.0,0.9);
     309 
     310  glEnable( GL_AUTO_NORMAL);
     311  glEnableClientState(GL_VERTEX_ARRAY );
     312  glEnableClientState(GL_TEXTURE_COORD_ARRAY );
    271313  for(int i = 0; i < Face->n_meshverts  ; i++) {
    272     //glFrontFace(GL_CW);
     314    glFrontFace(GL_CW);
    273315    //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]);
    274     glEnableClientState(GL_VERTEX_ARRAY );
    275     glEnableClientState(GL_TEXTURE_COORD_ARRAY );
     316 
     317 
    276318    glEnableClientState(GL_NORMAL_ARRAY );
    277319
    278320    glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0]));
     321   
     322   
     323    glClientActiveTextureARB(GL_TEXTURE0_ARB);
    279324    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0]));
     325    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     326
     327   
     328    glClientActiveTextureARB(GL_TEXTURE1_ARB);
     329    glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0]));
     330    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     331
     332   
    280333    glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) );
    281334
     
    291344                     & (     (((GLuint*)  (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8]  ))  );
    292345    }
    293 
    294     //glFrontFace(GL_CCW);
    295   }
    296 
     346   
     347    glFrontFace(GL_CCW);
     348  }
     349  glDisableClientState(GL_TEXTURE0_ARB);
     350  glDisableClientState(GL_TEXTURE1_ARB);
     351  glDisable(GL_AUTO_NORMAL);
     352  glDisableClientState(GL_VERTEX_ARRAY );
     353  glDisableClientState(GL_TEXTURE_COORD_ARRAY );
     354 
     355  glBegin(GL_QUADS);
     356 
     357  glEnd();
    297358}
    298359
     
    408469  glNormal3f( 1.0f, 0.0f, 0.0f);  glColor4f(0.2,0.2,0.9,.25);
    409470
    410   glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f, cam->z -1.0f);
     471  glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y -1.0f, cam->z -1.0f);
    411472  glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f);
    412473  glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z + 1.0f);
  • branches/bsp_model/src/lib/graphics/importer/material.cc

    r7221 r7465  
    8989  this->setName(m.getName());
    9090}
    91 
     91 
     92bool Material::select0() const
     93{
     94  glActiveTextureARB(GL_TEXTURE0_ARB);
     95  glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
     96  glEnable(GL_TEXTURE_2D);
     97 
     98}
    9299
    93100/**
     
    162169/**
    163170 *  Sets the Material Diffuse Color.
    164  * @param r Red Color Channel.
     171 * @param r Red Color Channel.a
    165172 * @param g Green Color Channel.
    166173 * @param b Blue Color Channel.
  • branches/bsp_model/src/lib/graphics/importer/material.h

    r7221 r7465  
    3232
    3333  bool select () const;
    34 
     34  bool select0 () const;
     35     
    3536  void setIllum (int illum);
    3637  void setIllum (char* illum);
  • branches/bsp_model/src/lib/graphics/importer/texture.cc

    r7221 r7465  
    264264  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
    265265
    266   glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/);
     266  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    267267  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    268268
Note: See TracChangeset for help on using the changeset viewer.