Changeset 7510 in orxonox.OLD for branches/bsp_model/src/lib
- Timestamp:
- May 3, 2006, 2:37:13 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
r7507 r7510 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch … … 222 222 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 223 223 this->load_textures(); 224 224 225 225 // Load the lightMaps 226 226 this->glLightMapTextures = new GLuint[this->numLightMaps]; 227 227 for(int i = 0; i < this->numLightMaps; i++) 228 228 this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); 229 229 230 230 //Create white texture for if no lightmap specified 231 231 glGenTextures(1, &this->whiteLightMap); 232 232 glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); 233 233 //Create texture 234 234 this->whiteTexture[0]=255; 235 235 this->whiteTexture[1]=255; 236 236 this->whiteTexture[2]=255; 237 237 238 238 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 239 239 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); … … 244 244 245 245 246 246 247 247 /* control the mipmap levels */ 248 248 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); … … 260 260 (const GLvoid *)&(this->whiteTexture)); 261 261 262 gluBuild2DMipmaps( 262 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, 263 263 GL_RGB, GL_FLOAT,(const GLvoid *) &(this->whiteTexture)); 264 265 264 265 266 266 267 267 // Get the number of patches … … 324 324 float z1 =(((plane *) this->planes) [planeIndex]).z; 325 325 thisNode->leafIndex = 0; 326 thisNode->d 326 thisNode->d = (((plane *) this->planes) [planeIndex]).d; 327 327 328 328 thisNode->plane = Vector(x1,y1,z1); … … 464 464 PRINTF(0)("BSP FILE: gefunden . \n"); 465 465 this->Materials[i] =this->loadMat(fileName); 466 466 467 467 } 468 468 … … 480 480 continue; 481 481 } 482 // 482 // Default Material 483 483 this->Materials[i].mat = new Material(); 484 484 this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); … … 503 503 if(this->testSurf != NULL) { 504 504 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; 505 else 505 else tmpAMat.alpha = false; 506 506 } else tmpAMat.alpha = false; 507 507 … … 510 510 tmp->setAmbient(1.0,1.0,1.0 ); 511 511 tmp->setSpecular(1.0,1.0,1.0); 512 // 513 // 512 // tmp->setShininess(.5); 513 // tmp->setTransparency(1.0); 514 514 515 515 tmp->setDiffuseMap(mat); … … 539 539 scale*=255.0; 540 540 sc*=scale; 541 ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc; 542 543 541 ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc; 542 543 544 544 } 545 545 546 546 glGenTextures(1, &lightMap); 547 547 glBindTexture(GL_TEXTURE_2D, lightMap); … … 569 569 (const GLvoid *)&lightMapTexture); 570 570 571 571 572 572 // build the MipMaps automaticaly 573 573 errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D, … … 579 579 (const GLvoid *)&lightMapTexture 580 580 ); 581 581 582 582 583 583 … … 715 715 716 716 717 //Vertice[u*(tesselation+1)+v]= 717 //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); 718 718 Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px); 719 719 Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px); -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r7465 r7510 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch … … 51 51 // Draw Debug Terrain 52 52 /* 53 this->bspFile->Materials[0]->select(); 53 this->bspFile->Materials[0]->select(); 54 54 for(int i = 0; i < this->bspFile->numPatches ; i++) 55 56 57 58 55 { 56 this->bspFile->VertexArrayModels[i]->draw(); 57 58 } 59 59 */ 60 60 … … 103 103 if (f >=0 && !this->isAlreadyVisible(f)) { 104 104 this->alreadyVisible[f] = true; 105 /* 106 107 108 109 110 }105 /* if(ActLeaf->leafIndex == i)public final double readLEDouble() 106 { 107 this->alreadyVisible[i] = false; 108 this->draw_debug_face(f); 109 this->alreadyVisible[i] = true; 110 } 111 111 else */ 112 112 addFace(f); // "visibleFaces.append(f)" … … 131 131 leaf& curLeaf = (this->bspFile->leaves)[i] ; 132 132 cluster = curLeaf.cluster; 133 133 134 134 if(cluster <0) continue; 135 135 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8)); 136 136 visSet =((unsigned char*) (this->bspFile->visData))[v+8]; 137 138 137 138 139 139 if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) == 0 ) 140 140 { … … 191 191 // if(this->bspFile->Materials[curFace.texture] != NULL) 192 192 //if(this->lastTex != curFace.texture) { 193 this->bspFile->Materials[curFace.texture].mat->select 0();193 this->bspFile->Materials[curFace.texture].mat->select(); 194 194 // this->lastTex = curFace.texture; 195 195 //} 196 197 if(curFace.lm_index < 0) 196 197 if(curFace.lm_index < 0) 198 198 { 199 199 glActiveTextureARB(GL_TEXTURE1_ARB); … … 207 207 glEnable(GL_TEXTURE_2D); 208 208 } 209 209 210 210 glColor4f(3.0,3.0,3.0,0.9); 211 211 glEnableClientState(GL_VERTEX_ARRAY ); … … 213 213 glEnableClientState(GL_NORMAL_ARRAY ); 214 214 // glEnableClientState(GL_COLOR_ARRAY); 215 215 216 216 217 217 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 218 218 219 219 glClientActiveTextureARB(GL_TEXTURE0_ARB); 220 220 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0])); 221 221 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 222 222 223 223 glClientActiveTextureARB(GL_TEXTURE1_ARB); 224 224 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1])); 225 225 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 226 226 227 227 228 228 glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0])); 229 229 // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0])); … … 288 288 { 289 289 if(this->lastTex != Face->texture) { 290 this->bspFile->Materials[Face->texture].mat->select 0();290 this->bspFile->Materials[Face->texture].mat->select(); 291 291 this->lastTex = Face->texture; 292 292 } 293 294 295 296 if(Face->lm_index < 0) 293 294 295 296 if(Face->lm_index < 0) 297 297 { 298 298 glActiveTextureARB(GL_TEXTURE1_ARB); … … 307 307 } 308 308 glColor4f(3.0,3.0,3.0,0.9); 309 309 310 310 glEnable( GL_AUTO_NORMAL); 311 311 glEnableClientState(GL_VERTEX_ARRAY ); … … 314 314 glFrontFace(GL_CW); 315 315 //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]); 316 317 316 317 318 318 glEnableClientState(GL_NORMAL_ARRAY ); 319 319 320 320 glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0])); 321 322 321 322 323 323 glClientActiveTextureARB(GL_TEXTURE0_ARB); 324 324 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0])); 325 325 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 326 326 327 327 328 328 glClientActiveTextureARB(GL_TEXTURE1_ARB); 329 329 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[1][0])); 330 330 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 331 331 332 332 333 333 glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 334 334 … … 344 344 & ( (((GLuint*) (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8] )) ); 345 345 } 346 346 347 347 glFrontFace(GL_CCW); 348 348 } … … 352 352 glDisableClientState(GL_VERTEX_ARRAY ); 353 353 glDisableClientState(GL_TEXTURE_COORD_ARRAY ); 354 354 355 355 glBegin(GL_QUADS); 356 356 357 357 glEnd(); 358 358 } … … 406 406 407 407 /* 408 409 410 411 412 413 414 415 416 plane&testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes];417 dist = testPlane.x * this->cam.x + testPlane.y * this->cam.y + testPlane.z * this->cam.z -testPlane.d ;418 419 420 421 422 423 424 425 426 408 for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ ) 409 { 410 brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes]; 411 if(curBrush.n_brushsides < 0) return; 412 for(int j = 0; j < curBrush.n_brushsides; j++) 413 { 414 float dist = -0.1; 415 brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides]; 416 plane& testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes]; 417 dist = testPlane.x * this->cam.x + testPlane.y * this->cam.y + testPlane.z * this->cam.z -testPlane.d ; 418 419 if(dist < -0.01f) dist = -1.0f *dist; 420 if(dist < 1.0f){ 421 this->drawDebugCube(&this->cam); 422 return; 423 } 424 } 425 426 } */ 427 427 428 428 } -
branches/bsp_model/src/lib/graphics/importer/material.cc
r7465 r7510 45 45 this->setTransparency(1.0); 46 46 47 this->diffuseTexture = NULL;48 47 this->ambientTexture = NULL; 49 48 this->specularTexture = NULL; … … 61 60 PRINTF(5)("delete Material %s.\n", this->getName()); 62 61 63 if (this->diffuseTexture != NULL) 64 { 65 ResourceManager::getInstance()->unload(this->diffuseTexture); 66 } 62 while(!this->textures.empty()) 63 { 64 if (this->textures.back() != NULL) 65 ResourceManager::getInstance()->unload(this->textures.back()); 66 this->textures.pop_back(); 67 } 68 67 69 if (this->ambientTexture != NULL) 68 70 ResourceManager::getInstance()->unload(this->ambientTexture); … … 71 73 } 72 74 73 Material& Material::operator=(const Material& m) 74 { 75 this->setIllum(m.illumModel); 76 this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]); 77 this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]); 78 this->setSpecular(m.specular[0],m.specular[1],m.specular[2]); 79 this->setShininess(m.shininess); 80 this->setTransparency(m.transparency); 81 82 if (this->diffuseTexture != NULL) 83 ResourceManager::getInstance()->unload(this->diffuseTexture); 84 if (m.diffuseTexture != NULL) 85 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture); 86 this->ambientTexture = NULL; /// FIXME 87 this->specularTexture = NULL; /// FIXME 88 89 this->setName(m.getName()); 90 } 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 } 75 76 /// TODO FIX THIS 77 // Material& Material::operator=(const Material& m) 78 // { 79 // this->setIllum(m.illumModel); 80 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]); 81 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]); 82 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]); 83 // this->setShininess(m.shininess); 84 // this->setTransparency(m.transparency); 85 // 86 // if (this->diffuseTexture != NULL) 87 // ResourceManager::getInstance()->unload(this->diffuseTexture); 88 // if (m.diffuseTexture != NULL) 89 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture); 90 // this->ambientTexture = NULL; /// FIXME 91 // this->specularTexture = NULL; /// FIXME 92 // 93 // this->setName(m.getName()); 94 // } 95 96 const GLenum Material::glTextureArbs[] = 97 { 98 GL_TEXTURE0_ARB, 99 GL_TEXTURE1_ARB, 100 GL_TEXTURE2_ARB, 101 GL_TEXTURE3_ARB, 102 GL_TEXTURE4_ARB, 103 GL_TEXTURE5_ARB, 104 GL_TEXTURE6_ARB, 105 GL_TEXTURE7_ARB 106 }; 107 99 108 100 109 /** 101 110 * sets the material with which the following Faces will be painted 102 111 */ 103 bool Material::select 112 bool Material::select() const 104 113 { 105 114 // setting diffuse color 106 115 glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency); 107 // glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);108 109 116 // setting ambient color 110 117 glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient); 111 112 118 // setting up Sprecular 113 119 glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular); 114 115 120 // setting up Shininess 116 121 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 117 122 123 118 124 // setting the transparency 119 125 if (this->transparency < 1.0 || /* This allows alpha blending of 2D textures with the scene */ 120 ( this->diffuseTexture && this->diffuseTexture->hasAlpha()))126 (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha())) 121 127 { 122 128 glEnable(GL_BLEND); … … 124 130 } 125 131 else 126 { 127 glDisable(GL_BLEND); 128 //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1); 129 } 132 { 133 glDisable(GL_BLEND); 134 } 130 135 131 136 … … 136 141 glShadeModel(GL_SMOOTH); 137 142 138 if (this->diffuseTexture != NULL) 143 144 for(unsigned int i = 0; i < this->textures.size(); ++i) 145 { 146 if (likely(this->textures[i] != NULL)) 139 147 { 148 glActiveTexture(Material::glTextureArbs[i]); 140 149 glEnable(GL_TEXTURE_2D); 141 glBindTexture(GL_TEXTURE_2D, this-> diffuseTexture->getTexture());150 glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture()); 142 151 } 143 else 144 { 145 glDisable(GL_TEXTURE_2D); 146 glBindTexture(GL_TEXTURE_2D, 0); 147 } 152 } 153 154 /* if (this->diffuseTexture != NULL) 155 { 156 glEnable(GL_TEXTURE_2D); 157 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 158 } 159 else 160 { 161 glDisable(GL_TEXTURE_2D); 162 glBindTexture(GL_TEXTURE_2D, 0); 163 }*/ 148 164 } 149 165 … … 233 249 this->specular[2] = b; 234 250 this->specular[3] = 1.0; 235 251 } 236 252 237 253 /** … … 296 312 * @param dMap the Name of the Image to Use 297 313 */ 298 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 299 { 314 void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber) 315 { 316 assert(textureNumber < Material::getMaxTextureUnits()); 317 300 318 PRINTF(5)("setting Diffuse Map %s\n", dMap); 301 if (this->diffuseTexture != NULL) 302 ResourceManager::getInstance()->unload(this->diffuseTexture); 319 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 320 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 321 322 if (this->textures.size() <= textureNumber) 323 this->textures.resize(textureNumber+1, NULL); 303 324 304 325 //! @todo check if RESOURCE MANAGER is availiable 305 //! @todo Textures from .mtl-file need special care.306 326 if (!dMap.empty()) 307 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 327 { 328 329 this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 330 } 308 331 else 309 this->diffuseTexture = NULL; 332 { 333 this->textures[textureNumber] = NULL; 334 } 310 335 } 311 336 … … 339 364 void Material::setBump(const std::string& bump) 340 365 { 341 342 } 366 } 367 368 369 370 int Material::getMaxTextureUnits() 371 { 372 int maxTexUnits = 0; 373 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); 374 return maxTexUnits; 375 } -
branches/bsp_model/src/lib/graphics/importer/material.h
r7465 r7510 14 14 #endif /* HAVE_CONFIG_H */ 15 15 16 #ifndef NULL 17 #define NULL 0 //!< a pointer to NULL 18 #endif 16 #include <vector> 17 19 18 20 19 #include "texture.h" … … 25 24 class Material : public BaseObject 26 25 { 27 public:28 Material (const std::string& mtlName = "");29 virtual ~Material ();26 public: 27 Material (const std::string& mtlName = ""); 28 virtual ~Material (); 30 29 31 Material& operator=(const Material& material);30 Material& operator=(const Material& material); 32 31 33 bool select () const; 34 bool select0 () const; 35 36 void setIllum (int illum); 37 void setIllum (char* illum); 38 int getIllumModel() const { return this->illumModel; }; 39 void setDiffuse (float r, float g, float b); 40 void setDiffuse (char* rgb); 41 void setAmbient (float r, float g, float b); 42 void setAmbient (char* rgb); 43 void setSpecular (float r, float g, float b); 44 void setSpecular (char* rgb); 45 void setShininess (float shini); 46 void setShininess (char* shini); 47 void setTransparency (float trans); 48 void setTransparency (char* trans); 49 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 32 bool select () const; 50 33 51 // MAPPING // 52 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D); 53 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 54 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 55 void setBump(const std::string& bump); 56 GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; }; 34 void setIllum (int illum); 35 int getIllumModel() const { return this->illumModel; }; 36 void setDiffuse (float r, float g, float b); 37 void setAmbient (float r, float g, float b); 38 void setSpecular (float r, float g, float b); 39 void setShininess (float shini); 40 void setTransparency (float trans); 41 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 57 42 58 static void addTexturePath(const std::string& pathName); 43 44 // TODO Move them out of here 45 void setIllum (char* illum); 46 void setDiffuse (char* rgb); 47 void setAmbient (char* rgb); 48 void setSpecular (char* rgb); 49 void setShininess (char* shini); 50 void setTransparency (char* trans); 51 52 53 // MAPPING // 54 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 55 56 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 57 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 58 void setBump(const std::string& bump); 59 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i]->getTexture() : 0; }; 60 61 static void addTexturePath(const std::string& pathName); 62 63 public: 64 static const GLenum glTextureArbs[]; //!< The Texture ARB's 65 66 static int getMaxTextureUnits(); 59 67 60 68 private: … … 68 76 GLenum tFactor; 69 77 70 Texture* diffuseTexture; //!< The diffuse texture of the Material. 78 std::vector<Texture*> textures; //!< An Array of Textures. 79 71 80 Texture* ambientTexture; //!< The ambient texture of the Material. 72 81 Texture* specularTexture; //!< The specular texture of the Material. 82 83 73 84 }; 74 85 #endif -
branches/bsp_model/src/lib/graphics/render2D/billboard.cc
r7221 r7510 78 78 void Billboard::loadParams(const TiXmlElement* root) 79 79 { 80 LoadParam(root, "texture", this ->material, Material, setDiffuseMap)80 LoadParam(root, "texture", this, Billboard, setTexture) 81 81 .describe("the texture-file to load onto the Billboard"); 82 82
Note: See TracChangeset
for help on using the changeset viewer.