Changeset 7465 in orxonox.OLD for branches/bsp_model
- Timestamp:
- May 1, 2006, 9:08:19 PM (19 years ago)
- 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 181 181 bspFile.read((char*)this->faces, size); 182 182 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 183 192 // Get the Visdata 184 193 offset = SDL_SwapLE32(((int *)(header))[34]); … … 213 222 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 214 223 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 215 266 216 267 // Get the number of patches … … 413 464 PRINTF(0)("BSP FILE: gefunden . \n"); 414 465 this->Materials[i] =this->loadMat(fileName); 415 continue;466 416 467 } 417 468 … … 471 522 } 472 523 524 unsigned 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, 574 GL_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 473 589 void BspFile::tesselate(int iface) 474 590 { … … 784 900 // Overwrite Face->meshvert; 785 901 // Overwrite Face->n_meshverts; 786 int sz = ( Face->size[0] -1)/2 * (Face->size[1]-1)/2; // num patches902 int sz = (size0 -1)/2 * (size1 -1)/2; // num patches 787 903 Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; 788 904 Face->n_meshverts = sz; -
branches/bsp_model/src/lib/graphics/importer/bsp_file.h
r7410 r7465 88 88 int lm_index; //!< Lightmap index. 89 89 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. 91 91 float lm_origin [ 3 ] ; //!< World space origin of lightmap. 92 92 float lm_vecs [ 2 ][ 3 ]; //!< World space lightmap s and t unit vectors. … … 123 123 AMat; 124 124 125 typedef struct 126 { 127 unsigned char map [128][128][3]; 128 } 129 lightmap; 130 125 131 class BspFile 126 132 { … … 153 159 char* visData; //!< 154 160 char* textures; //!< 155 char* patchVertice; 161 char* patchVertice; //!< 156 162 char* patchIndexes; 157 163 char* patchTrianglesPerRow; 158 159 164 lightmap* lightMaps; //!< Buffer to store lightmap-images 165 166 160 167 int** patchRowIndexes; 161 168 VertexArrayModel** VertexArrayModels; … … 173 180 int numPatches; 174 181 int numBrushSides; 182 int numLightMaps; 175 183 176 184 BspTreeNode* build_tree_rec( int i ); 185 unsigned int loadLightMapToGL(lightmap&); 177 186 AMat* Materials; 187 unsigned int* glLightMapTextures; 188 unsigned int whiteLightMap; 189 unsigned char whiteTexture[3]; 178 190 SDL_Surface* testSurf; 179 191 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r7395 r7465 87 87 this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 88 88 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) 90 90 { 91 91 /** Do Frustum culling and draw 'em all **/ 92 92 93 // Iterate through all Leafs 93 // Iterate through all Leafspublic final double readLEDouble() 94 94 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) 95 95 { … … 103 103 if (f >=0 && !this->isAlreadyVisible(f)) { 104 104 this->alreadyVisible[f] = true; 105 /* if(ActLeaf->leafIndex == i) 105 /* if(ActLeaf->leafIndex == i)public final double readLEDouble() 106 106 { 107 107 this->alreadyVisible[i] = false; … … 190 190 if(curFace.type == 3) return; 191 191 // 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); 196 211 glEnableClientState(GL_VERTEX_ARRAY ); 197 glEnableClientState(GL_TEXTURE_COORD_ARRAY );212 //glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 198 213 glEnableClientState(GL_NORMAL_ARRAY ); 199 214 // glEnableClientState(GL_COLOR_ARRAY); … … 201 216 202 217 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 203 // glClientActiveTextureARB(GL_TEXTURE0_ARB); 218 219 glClientActiveTextureARB(GL_TEXTURE0_ARB); 204 220 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 209 228 glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0])); 210 229 // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0])); … … 212 231 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert])); 213 232 214 233 glDisableClientState(GL_TEXTURE0_ARB); 234 glDisableClientState(GL_TEXTURE1_ARB); 215 235 glDisableClientState(GL_VERTEX_ARRAY ); 216 glDisableClientState(GL_TEXTURE_COORD_ARRAY );236 //glDisableClientState(GL_TEXTURE_COORD_ARRAY ); 217 237 glDisableClientState(GL_NORMAL_ARRAY ); 218 238 // glDisableClientState(GL_COLOR_ARRAY); … … 247 267 //glEnableClientState(GL_COLOR_ARRAY); 248 268 // glEnableClientState(GL_VERTEX_ARRAY ); 249 269 glClientActiveTextureARB(GL_TEXTURE0_ARB); 250 270 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 271 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 251 272 // glClientActiveTextureARB(GL_TEXTURE0_ARB); 273 glClientActiveTextureARB(GL_TEXTURE1_ARB); 252 274 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0])); 275 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 253 276 // glClientActiveTextureARB(GL_TEXTURE1_ARB); 254 277 // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1])); … … 265 288 { 266 289 if(this->lastTex != Face->texture) { 267 this->bspFile->Materials[Face->texture].mat->select ();290 this->bspFile->Materials[Face->texture].mat->select0(); 268 291 this->lastTex = Face->texture; 269 292 } 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 ); 271 313 for(int i = 0; i < Face->n_meshverts ; i++) { 272 //glFrontFace(GL_CW);314 glFrontFace(GL_CW); 273 315 //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 276 318 glEnableClientState(GL_NORMAL_ARRAY ); 277 319 278 320 glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0])); 321 322 323 glClientActiveTextureARB(GL_TEXTURE0_ARB); 279 324 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 280 333 glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 281 334 … … 291 344 & ( (((GLuint*) (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8] )) ); 292 345 } 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(); 297 358 } 298 359 … … 408 469 glNormal3f( 1.0f, 0.0f, 0.0f); glColor4f(0.2,0.2,0.9,.25); 409 470 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); 411 472 glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f); 412 473 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 89 89 this->setName(m.getName()); 90 90 } 91 91 92 bool Material::select0() const 93 { 94 glActiveTextureARB(GL_TEXTURE0_ARB); 95 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 96 glEnable(GL_TEXTURE_2D); 97 98 } 92 99 93 100 /** … … 162 169 /** 163 170 * Sets the Material Diffuse Color. 164 * @param r Red Color Channel. 171 * @param r Red Color Channel.a 165 172 * @param g Green Color Channel. 166 173 * @param b Blue Color Channel. -
branches/bsp_model/src/lib/graphics/importer/material.h
r7221 r7465 32 32 33 33 bool select () const; 34 34 bool select0 () const; 35 35 36 void setIllum (int illum); 36 37 void setIllum (char* illum); -
branches/bsp_model/src/lib/graphics/importer/texture.cc
r7221 r7465 264 264 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 265 265 266 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR /*_MIPMAP_LINEAR*/);266 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 267 267 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 268 268
Note: See TracChangeset
for help on using the changeset viewer.