Changeset 9324 in orxonox.OLD for branches/terrain/src/lib/graphics/importer
- Timestamp:
- Jul 18, 2006, 12:04:54 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/bsp_file.cc
r9025 r9324 21 21 #include "bsp_file.h" 22 22 #include "bsp_tree_node.h" 23 #include <fstream>24 23 #include "util/loading/resource_manager.h" 25 24 #include <string> 26 25 #include <sys/stat.h> 27 26 #include <string.h> 27 #include "filesys/binary_file.h" 28 28 #include "debug.h" 29 29 #include "material.h" … … 42 42 using namespace std; 43 43 44 static const char* HEADER_SEMANTICS = "b4i35"; 45 static const char* NODE_SEMANTICS = "i9"; 46 static const char* LEAF_SEMANTICS = "i12"; 47 static const char* MODEL_SEMANTICS = "i10"; 48 static const char* BRUSH_SEMANTICS = "i3"; 49 static const char* BRUSHSIDE_SEMANTICS = "i2"; 50 static const char* FACE_SEMANTICS = "i26"; 51 static const char* VERTEX_SEMANTICS = "i10b4"; 52 static const char* LIGHTMAP_SEMANTICS = "b49152"; 53 static const char* TEXTURE_SEMANTICS = "b64i2"; 54 static const char* PLANE_SEMANTICS = "f4"; 44 55 45 56 // Constructor … … 81 92 82 93 } 83 94 void BspFile::readEntities() 95 { 96 /* We do nothing here */ 97 } 98 void BspFile::readTextures() 99 { 100 size_t slurpedBytes; 101 bsp_lump& lump = header.lumps[Textures]; 102 this->numTextures = lump.length/sizeof(BspTexture); 103 this->textures = new char[lump.length]; 104 file.seekg( lump.offset ); 105 file.read( TEXTURE_SEMANTICS, this->numTextures, 106 this->textures, slurpedBytes ); 107 } 108 void BspFile::readPlanes() 109 { 110 size_t slurpedBytes; 111 bsp_lump& lump = header.lumps[Planes]; 112 this->numPlanes = lump.length/sizeof(plane); 113 this->planes = new plane[this->numPlanes]; 114 file.seekg( lump.offset ); 115 file.read( PLANE_SEMANTICS, this->numPlanes, 116 this->planes, slurpedBytes ); 117 } 118 119 void BspFile::readNodes() 120 { 121 size_t slurpedBytes; 122 bsp_lump& lump = header.lumps[Nodes]; 123 this->numNodes = lump.length/sizeof(node); 124 this->nodes = new node[this->numNodes]; 125 file.seekg( lump.offset ); 126 file.read( NODE_SEMANTICS, this->numNodes, 127 this->nodes, slurpedBytes ); 128 } 129 130 void BspFile::readLeafs() 131 { 132 size_t slurpedBytes; 133 bsp_lump& lump = header.lumps[Leafs]; 134 this->numLeafs = lump.length/sizeof(leaf); 135 this->leaves = new leaf[this->numLeafs]; 136 file.seekg( lump.offset ); 137 file.read( LEAF_SEMANTICS, this->numLeafs, 138 this->leaves, slurpedBytes ); 139 } 140 141 void BspFile::readLeafFaces() 142 { 143 size_t slurpedBytes; 144 bsp_lump& lump = header.lumps[Leaffaces]; 145 this->numLeafFaces = lump.length/sizeof(int); 146 this->leafFaces = (char*)( new int[this->numLeafFaces] ); 147 file.seekg( lump.offset ); 148 file.read( "i", this->numLeafFaces, 149 this->leafFaces, slurpedBytes ); 150 } 151 152 void BspFile::readLeafBrushes() 153 { 154 size_t slurpedBytes; 155 bsp_lump& lump = header.lumps[Leafbrushes]; 156 this->numLeafBrushes = lump.length/sizeof(int); 157 this->leafBrushes = (char*) ( new int[this->numLeafBrushes] ); 158 file.seekg( lump.offset ); 159 file.read( "i", this->numLeafBrushes, 160 this->leafBrushes, slurpedBytes ); 161 } 162 163 void BspFile::readModels() 164 { 165 size_t slurpedBytes; 166 bsp_lump& lump = header.lumps[Models]; 167 this->numBspModels = lump.length/sizeof(model); 168 this->bspModels = new model[this->numBspModels]; 169 file.seekg( lump.offset ); 170 file.read( MODEL_SEMANTICS, this->numBspModels, 171 this->bspModels, slurpedBytes ); 172 } 173 174 void BspFile::readBrushes() 175 { 176 size_t slurpedBytes; 177 bsp_lump& lump = header.lumps[Brushes]; 178 int numBrushes = lump.length/sizeof(brush); 179 this->brushes = new brush[numBrushes]; 180 file.seekg( lump.offset ); 181 file.read( BRUSH_SEMANTICS, numBrushes, 182 this->brushes, slurpedBytes ); 183 } 184 void BspFile::readVertices() 185 { 186 size_t slurpedBytes; 187 bsp_lump& lump = header.lumps[Vertices]; 188 this->numVertex = lump.length/sizeof(BspVertex); 189 this->vertice = (char*)( new BspVertex[this->numVertex] ); 190 file.seekg( lump.offset ); 191 file.read( VERTEX_SEMANTICS, this->numVertex, 192 this->vertice, slurpedBytes ); 193 } 194 195 void BspFile::readMeshVerts() 196 { 197 size_t slurpedBytes; 198 bsp_lump& lump = header.lumps[Meshverts]; 199 int num = lump.length / sizeof( meshvert ); 200 this->meshverts = new meshvert[num]; 201 file.seekg( lump.offset ); 202 file.read( "i", num, this->meshverts, slurpedBytes ); 203 } 204 205 void BspFile::readEffects() 206 { 207 /* not loaded atm */ 208 } 209 210 void BspFile::readFaces() 211 { 212 size_t slurpedBytes; 213 bsp_lump& lump = header.lumps[Faces]; 214 this->numFaces = lump.length/sizeof(face); 215 this->faces = new face[this->numFaces]; 216 file.seekg( lump.offset ); 217 file.read( FACE_SEMANTICS, this->numFaces, 218 this->faces, slurpedBytes ); 219 } 220 221 void BspFile::readLightmaps() 222 { 223 size_t slurpedBytes; 224 bsp_lump& lump = header.lumps[Lightmaps]; 225 this->numLightMaps = lump.length/sizeof(lightmap); 226 this->lightMaps = new lightmap[this->numLightMaps]; 227 file.seekg( lump.offset ); 228 file.read( LIGHTMAP_SEMANTICS, this->numLightMaps, 229 this->lightMaps, slurpedBytes ); 230 } 231 void BspFile::readLightvols() 232 { 233 /* not loaded atm */ 234 } 235 void BspFile::readBrushSides() 236 { 237 size_t slurpedBytes; 238 bsp_lump& lump = header.lumps[Brushsides]; 239 this->numBrushSides = lump.length/sizeof(brushside); 240 printf( "numBrushSides: %d\n", numBrushSides ); 241 this->brushSides = new brushside[this->numBrushSides]; 242 file.seekg( lump.offset ); 243 file.read( BRUSHSIDE_SEMANTICS, this->numBrushSides, 244 this->brushSides, slurpedBytes ); 245 } 246 void BspFile::readVisdata() 247 { 248 size_t slurpedBytes; 249 bsp_lump& lump = header.lumps[Visdata]; 250 this->visData = new char[lump.length]; 251 file.seekg( lump.offset ); 252 file.read( "i2", 1, this->visData, slurpedBytes ); 253 file.read( "b", lump.length-8, 254 this->visData+8, slurpedBytes ); 255 } 84 256 /** 85 257 * Loads a quake3 level (*.bsp) … … 88 260 int BspFile::read(const char* name) 89 261 { 90 this->scale = 1.0; 91 int offset; 92 int size; 93 struct stat results; 94 95 96 if (stat( name , &results) == 0) { 97 PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name); 98 ifstream bspFile (name, ios::in | ios::binary); 99 bspFile.read(this->header, 260); 100 PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]); 101 if(SDL_SwapLE32(((int *)(header) )[1]) == 46) PRINTF(0)("BSP FILE: This is the good one! :-) \n"); 102 else PRINTF(0)("BSP FILE: Wrong BSPVersion.\n"); //!< now, we should do some error handling 103 104 // Get the Nodes 105 offset = SDL_SwapLE32(((int *)(header) )[8]); 106 size = SDL_SwapLE32(((int *)(header))[9]); 107 PRINTF(4)("BSP FILE: NodeSize: %i Bytes. \n", size); 108 PRINTF(4)("BSP FILE: NumNodes: %i. \n", size / sizeof(node)); 109 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(node)); 110 PRINTF(4)("BSP FILE: NodeOffset: %i. \n", offset); 111 this->numNodes = size/sizeof(node); 112 this->nodes = new node [this->numNodes]; 113 bspFile.seekg(offset); 114 bspFile.read((char*)this->nodes, size); 115 116 // and their Planes 117 offset = SDL_SwapLE32(((int *)(header) )[6]); 118 size = SDL_SwapLE32(((int *)(header))[7]); 119 PRINTF(4)("BSP FILE: PlanesSize: %i Bytes. \n", size); 120 PRINTF(4)("BSP FILE: NumPlanes: %i. \n", size / sizeof(plane)); 121 PRINTF(4)("BSP FILE: Remainder: %i. \n", sizeof(plane)); 122 PRINTF(4)("BSP FILE: PlanesOffset: %i. \n", offset); 123 this->numPlanes = size/sizeof(plane); 124 this->planes = new plane [this->numPlanes]; 125 bspFile.seekg(offset); 126 bspFile.read((char*)this->planes, size); 127 128 // Get the Leafs 129 offset = SDL_SwapLE32(((int *)(header) )[10]); 130 size = SDL_SwapLE32(((int *)(header))[11]); 131 PRINTF(4)("BSP FILE: LeaveSize: %i Bytes. \n", size); 132 PRINTF(4)("BSP FILE: NumLeaves: %i. \n", size / sizeof(leaf)); 133 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(leaf)); 134 PRINTF(4)("BSP FILE: LeaveOffset: %i. \n", offset); 135 this->numLeafs = size/sizeof(leaf); 136 this->leaves = new leaf [this->numLeafs]; 137 bspFile.seekg(offset); 138 bspFile.read((char*)this->leaves, size); 139 140 // Get the Models 141 offset = SDL_SwapLE32(((int *)(header))[16]); 142 size = SDL_SwapLE32(((int *)(header))[17]); 143 PRINTF(4)("BSP FILE: ModelsSize: %i Bytes. \n", size); 144 PRINTF(4)("BSP FILE: NumModels: %i. \n", size / sizeof(model)); 145 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(model)); 146 PRINTF(4)("BSP FILE: ModelsOffset: %i. \n", offset); 147 this->numBspModels = size/sizeof(model); 148 this->bspModels = new model [this->numBspModels]; 149 bspFile.seekg(offset); 150 bspFile.read((char*)this->bspModels, size); 151 152 // Get the leafFaces 153 offset = SDL_SwapLE32(((int *)(header))[12]); 154 size = SDL_SwapLE32(((int *)(header))[13]); 155 PRINTF(4)("BSP FILE: leafFacesSize: %i Bytes. \n", size); 156 PRINTF(4)("BSP FILE: NumleafFaces: %i. \n", size / 4); 157 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); 158 PRINTF(4)("BSP FILE: leafFacesOffset: %i. \n", offset); 159 this->numLeafFaces = size/4; 160 this->leafFaces = new char [size]; 161 bspFile.seekg(offset); 162 bspFile.read(this->leafFaces, size); 163 164 // Get the leafBrushes 165 offset = SDL_SwapLE32(((int *)(header))[14]); 166 size = SDL_SwapLE32(((int *)(header))[15]); 167 PRINTF(4)("BSP FILE: leafBrushesSize: %i Bytes. \n", size); 168 PRINTF(4)("BSP FILE: NumleafBrushes: %i. \n", size / 4); 169 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); 170 PRINTF(4)("BSP FILE: leafBrushesOffset: %i. \n", offset); 171 this->numLeafBrushes = size/4; 172 this->leafBrushes = new char [size]; 173 bspFile.seekg(offset); 174 bspFile.read(this->leafBrushes, size); 175 176 // Get the brushes 177 offset = SDL_SwapLE32(((int *)(header))[18]); 178 size = SDL_SwapLE32(((int *)(header))[19]); 179 PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size); 180 PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / sizeof(brush)); 181 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(brush)); 182 PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset); 183 this->brushes = new brush [size/sizeof(brush)]; 184 bspFile.seekg(offset); 185 bspFile.read((char*)this->brushes, size); 186 187 // Get the brushSides 188 offset = SDL_SwapLE32(((int *)(header))[20]); 189 size = SDL_SwapLE32(((int *)(header))[21]); 190 PRINTF(4)("BSP FILE: BrushSidesSize: %i Bytes. \n", size); 191 PRINTF(4)("BSP FILE: NumBrushSides: %i. \n", size / 8); 192 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 8); 193 PRINTF(4)("BSP FILE: BrushSidesOffset: %i. \n", offset); 194 this->numBrushSides = size/sizeof(brushside); 195 this->brushSides = new brushside [this->numBrushSides]; 196 bspFile.seekg(offset); 197 bspFile.read((char*)this->brushSides, size); 198 199 // Get the Vertice 200 offset = SDL_SwapLE32(((int *)(header))[22]); 201 size = SDL_SwapLE32(((int *)(header))[23]); 202 PRINTF(4)("BSP FILE: VerticeSize: %i Bytes. \n", size); 203 PRINTF(4)("BSP FILE: NumVertice: %i. \n", size / 44); 204 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 44); 205 PRINTF(4)("BSP FILE: VerticeOffset: %i. \n", offset); 206 this->numVertex = size/44; 207 this->vertice = new char [size]; 208 bspFile.seekg(offset); 209 bspFile.read(this->vertice, size); 210 211 // Get the MeshVerts 212 offset = SDL_SwapLE32(((int *)(header))[24]); 213 size = SDL_SwapLE32(((int *)(header))[25]); 214 PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size); 215 PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / sizeof(meshvert)); 216 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(meshvert)); 217 PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset); 218 this->meshverts = new meshvert [size / sizeof(meshvert)]; 219 bspFile.seekg(offset); 220 bspFile.read((char*)this->meshverts, size); 221 222 // Get the Faces 223 offset = SDL_SwapLE32(((int *)(header))[28]); 224 size = SDL_SwapLE32(((int *)(header))[29]); 225 PRINTF(4)("BSP FILE: FacesSize: %i Bytes. \n", size); 226 PRINTF(4)("BSP FILE: NumFaces: %i. \n", size / sizeof(face)); 227 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(face)); 228 PRINTF(4)("BSP FILE: FacesOffset: %i. \n", offset); 229 this->numFaces = size/sizeof(face); 230 this->faces = new face [this->numFaces]; 231 bspFile.seekg(offset); 232 bspFile.read((char*)this->faces, size); 233 234 //Get the lightmaps 235 offset = SDL_SwapLE32(((int *)(header))[30]); 236 size = SDL_SwapLE32(((int *)(header))[31]); 237 this->numLightMaps = size/ sizeof(lightmap); 238 this->lightMaps = new lightmap [this->numLightMaps]; 239 bspFile.seekg(offset); 240 bspFile.read((char*)this->lightMaps, size); 241 242 243 // Get the Visdata 244 offset = SDL_SwapLE32(((int *)(header))[34]); 245 size = SDL_SwapLE32(((int *)(header))[35]); 246 247 this->visData = new char [size]; 248 bspFile.seekg(offset); 249 bspFile.read(this->visData, size); 250 251 PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size); 252 PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8); 253 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1); 254 PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset); 255 256 // Get the Textures 257 offset = SDL_SwapLE32(((int *)(header))[4]); 258 size = SDL_SwapLE32(((int *)(header))[5]); 259 260 this->textures= new char [size]; 261 bspFile.seekg(offset); 262 bspFile.read(this->textures, size); 263 264 PRINTF(4)("BSP FILE: TextureSize: %i Bytes. \n", size); 265 PRINTF(4)("BSP FILE: NumTextures: %i. \n", size /72); 266 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 72); 267 PRINTF(4)("BSP FILE: TextureOffset: %i. \n", offset); 268 this->numTextures = size/72; 269 270 bspFile.close(); 271 272 for(int i = 0 ; i < this->numTextures; i++) 273 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 274 this->load_textures(); 275 276 // Load the lightMaps 277 this->glLightMapTextures = new GLuint[this->numLightMaps]; 278 for(int i = 0; i < this->numLightMaps; i++) 279 this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); 280 281 //Create white texture for if no lightmap specified 282 glGenTextures(1, &this->whiteLightMap); 283 glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); 284 //Create texture 285 this->whiteTexture[0]=255; 286 this->whiteTexture[1]=255; 287 this->whiteTexture[2]=255; 288 289 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 290 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); 291 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 292 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 293 294 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); 295 296 297 298 /* control the mipmap levels */ 299 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 300 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 301 302 /* build the Texture OpenGL V >= 1.1 */ 303 glTexImage2D(GL_TEXTURE_2D, 304 0, 305 GL_RGBA8, 306 1, 307 1, 308 0, 309 GL_RGB, 310 GL_UNSIGNED_BYTE, 311 (const GLvoid *)&(this->whiteTexture)); 312 313 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, 314 GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); 315 316 317 318 // Get the number of patches 319 this->numPatches = 0; 320 this->patchOffset = 0; 321 322 for( int i = 0; i < this->numFaces; i++) { 323 face& cFace = ((face *)(this->faces))[i]; 324 if (SDL_SwapLE32(cFace.type) == 2) 325 this->numPatches += (SDL_SwapLE32(cFace.size[0]) -1 ) / 2 * (SDL_SwapLE32(cFace.size[1]) -1) / 2; 326 } 327 328 // Allocate Memory 329 this->patchVertice = new char[8*8*44*(this->numPatches+10)]; 330 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 331 // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed? 332 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 333 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; 334 335 PRINTF(4)("BSP FILE:NumberOfPatches: %i . \n", numPatches); 336 337 this->swapAllBspCoordinates(); 338 339 // Do tesselation for all Faces of type 2 340 for( int i = 0; i < this->numFaces; i++) { 341 if (SDL_SwapLE32((this->faces)[i].type) == 2) 342 this->tesselate(i); 343 } 344 345 PRINTF(4)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); 346 347 return 1; 348 } else { 349 PRINTF(4)("BSP FILE: Datei nicht gefunden. \n"); 350 return -1; 351 } 352 353 354 262 this->scale = 1.0; 263 264 size_t slurpedBytes; 265 string theBSPFile( name ); 266 file.setFileName( theBSPFile ); 267 if (file.exists() && file.open( File::ReadOnly ) ) { 268 PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name); 269 270 //BSP-Files have little endian order. 271 file.setByteorder( LittleEndian ); 272 file.read( HEADER_SEMANTICS, (void*)&header, slurpedBytes ); 273 if ( header.version != 46 ) { 274 PRINTF(0)("BSP FILE: Wrong BSPVersion. We only handle 0x2e-files!\n"); 275 //!< now, we should do some error handling 276 return ( -1 ); 277 } 278 readEntities(); 279 readTextures(); 280 readPlanes(); 281 readNodes(); 282 readLeafs(); readLeafFaces(); readLeafBrushes(); 283 readModels(); 284 readVertices(); readMeshVerts(); 285 readBrushSides(); readBrushes(); 286 readEffects(); 287 readFaces(); 288 readLightmaps(); readLightvols(); 289 readVisdata( 290 file.close(); 291 292 for(int i = 0 ; i < this->numTextures; i++) 293 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 294 this->load_textures(); 295 296 // Load the lightMaps 297 this->glLightMapTextures = new GLuint[this->numLightMaps]; 298 for(int i = 0; i < this->numLightMaps; i++) 299 this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); 300 301 //Create white texture for if no lightmap specified 302 glGenTextures(1, &this->whiteLightMap); 303 glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); 304 //Create texture 305 this->whiteTexture[0]=255; 306 this->whiteTexture[1]=255; 307 this->whiteTexture[2]=255; 308 309 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); 311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 313 314 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); 315 /* control the mipmap levels */ 316 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 317 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 318 319 /* build the Texture OpenGL V >= 1.1 */ 320 glTexImage2D(GL_TEXTURE_2D, 321 0, 322 GL_RGBA8, 323 1, 324 1, 325 0, 326 GL_RGB, 327 GL_UNSIGNED_BYTE, 328 (const GLvoid *)&(this->whiteTexture)); 329 330 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, 331 GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); 332 333 334 335 // Get the number of patches 336 this->numPatches = 0; 337 this->patchOffset = 0; 338 339 for( int i = 0; i < this->numFaces; i++) { 340 face& cFace = ((face *)(this->faces))[i]; 341 if ( cFace.type == 2) 342 this->numPatches += ( cFace.size[0] -1 ) / 2 * ( cFace.size[1] -1 ) / 2; 343 } 344 345 // Allocate Memory 346 this->patchVertice = new char[8*8*44*(this->numPatches+10)]; 347 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 348 // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed? 349 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 350 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; 351 352 PRINTF(4)("BSP FILE:NumberOfPatches: %i . \n", numPatches); 353 354 this->swapAllBspCoordinates(); 355 356 // Do tesselation for all Faces of type 2 357 for( int i = 0; i < this->numFaces; i++) { 358 if ( (this->faces)[i].type == 2) 359 this->tesselate(i); 360 } 361 362 PRINTF(4)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); 363 364 return 1; 365 } else { 366 PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); 367 return -1; 368 } 355 369 } 356 370 … … 430 444 char fileName [500]; 431 445 char ext [500]; 432 struct stat results;446 //struct stat results; 433 447 434 448 … … 660 674 int errorCode = 0; //!< the error code for the texture loading functions 661 675 unsigned int lightMap; //!< the OpenGL texture handle 662 int mipmapLevel = 0; //!< the maximum mipmap level for this texture676 /* int mipmapLevel = 0; //!< the maximum mipmap level for this texture 663 677 int mipmapWidth = 0; //!< the width of the mipmap 664 int mipmapHight = 0; //!< the height of the mipmap3 678 int mipmapHight = 0; //!< the height of the mipmap3*/ 665 679 float sc, scale, temp; 666 680 for(int i = 0; i < 128*128*3 ; i++) -
branches/terrain/src/lib/graphics/importer/bsp_file.h
r9003 r9324 19 19 20 20 #include <vector> 21 #include "filesys/binary_file.h" 21 22 class SDL_Surface; 22 23 class BspTreeNode; … … 27 28 28 29 29 struct plane 30 struct bsp_lump { 31 int offset; 32 int length; 33 }; 34 35 enum bsp_lumps { 36 Entities = 0, 37 Textures = 1, 38 Planes = 2, 39 Nodes = 3, 40 Leafs = 4, 41 Leaffaces = 5, 42 Leafbrushes = 6, 43 Models = 7, 44 Brushes = 8, 45 Brushsides = 9, 46 Vertices = 10, 47 Meshverts = 11, 48 Effects = 12, 49 Faces = 13, 50 Lightmaps = 14, 51 Lightvols = 15, 52 Visdata = 16 53 }; 54 55 struct bsp_header { 56 // The magic number always "IBSP" 57 char magic[4]; 58 // The version, 0x2e for quake 3 models 59 int version; 60 bsp_lump lumps[17]; 61 }; 62 63 struct plane 30 64 { 31 65 float x; //!< 1st component of the plane's normal … … 34 68 float d; //!< distance of the plane to the origin 35 69 }; 70 36 71 37 72 typedef struct … … 82 117 } 83 118 brushside; 119 84 120 85 121 struct face … … 101 137 } ; 102 138 139 103 140 typedef struct 104 141 { … … 130 167 } 131 168 AMat; 132 133 169 typedef struct 134 170 { … … 144 180 } 145 181 BspTexture; 182 146 183 147 184 class BspFile … … 162 199 163 200 private: 164 BspTreeNode* root; 165 char header [ 280 ]; //!< Buffer for header of BSP-File 166 node* nodes; //!< Buffer to store BSP-Tree-Nodes 167 leaf* leaves; //!< Buffer to store BSP-Tree-Leaves 168 plane* planes; //!< Buffer to store planes separateing the space 169 model* bspModels; //!< Buffer to store BSP-Model-List 170 char* leafFaces; //!< Buffer to store leafFaces 171 face* faces; //!< 172 char* leafBrushes; //!< Buffer to store brush indice 173 brush* brushes; //!< Buffer to store brushes 174 brushside* brushSides; //!< 175 char* vertice; //!< 176 meshvert* meshverts; //!< Buffer to store meshverice 177 char* visData; //!< Buffer to store visibility data 178 char* textures; //!< Holds all the texture filename strings 179 char* patchVertice; //!< 180 char* patchIndexes; 181 char* patchTrianglesPerRow; 182 lightmap* lightMaps; //!< Buffer to store lightmap-images 183 184 185 int** patchRowIndexes; 186 VertexArrayModel** VertexArrayModels; 187 int patchOffset; 188 189 int numNodes; 190 int numLeafs; 191 int numVertex; 192 int numPlanes; 193 int numBspModels; 194 int numLeafFaces; 195 int numFaces; 196 int numLeafBrushes; 197 int numTextures; 198 int numPatches; 199 int numBrushSides; 200 int numLightMaps; 201 202 float scale; 203 204 BspTreeNode* build_tree_rec( int i ); 205 unsigned int loadLightMapToGL(lightmap&); 206 AMat* Materials; 207 unsigned int* glLightMapTextures; 208 unsigned int whiteLightMap; 209 unsigned char whiteTexture[3]; 210 void swapAllBspCoordinates(); 211 void swapCoords(int * array); 212 void swapCoords(float * array); 213 SDL_Surface* testSurf; 214 215 216 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 217 }; 218 201 void readEntities(); 202 void readTextures(); 203 void readPlanes(); 204 void readNodes(); 205 void readLeafs(); 206 void readLeafFaces(); 207 void readLeafBrushes(); 208 void readBrushSides(); 209 void readModels(); 210 void readBrushes(); 211 void readVertices(); 212 void readMeshVerts(); 213 void readEffects(); 214 void readFaces(); 215 void readLightmaps(); 216 void readLightvols(); 217 void readVisdata(); 218 BinaryFile file; 219 BspTreeNode* root; 220 bsp_header header; //!< Buffer for header of BSP-File 221 node* nodes; //!< Buffer to store BSP-Tree-Nodes 222 leaf* leaves; //!< Buffer to store BSP-Tree-Leaves 223 plane* planes; //!< Buffer to store planes separateing the space 224 model* bspModels; //!< Buffer to store BSP-Model-List 225 char* leafFaces; //!< Buffer to store leafFaces 226 face* faces; //!< 227 char* leafBrushes; //!< Buffer to store brush indice 228 brush* brushes; //!< Buffer to store brushes 229 brushside* brushSides; //!< 230 char* vertice; //!< 231 meshvert* meshverts; //!< Buffer to store meshverice 232 char* visData; //!< Buffer to store visibility data 233 char* textures; //!< Holds all the texture filename strings 234 char* patchVertice; //!< 235 char* patchIndexes; 236 char* patchTrianglesPerRow; 237 lightmap* lightMaps; //!< Buffer to store lightmap-images 238 239 240 int** patchRowIndexes; 241 VertexArrayModel** VertexArrayModels; 242 int patchOffset; 243 244 int numNodes; 245 int numLeafs; 246 int numVertex; 247 int numPlanes; 248 int numBspModels; 249 int numLeafFaces; 250 int numFaces; 251 int numLeafBrushes; 252 int numTextures; 253 int numPatches; 254 int numBrushSides; 255 int numLightMaps; 256 257 float scale; 258 259 BspTreeNode* build_tree_rec( int i ); 260 unsigned int loadLightMapToGL(lightmap&); 261 AMat* Materials; 262 unsigned int* glLightMapTextures; 263 unsigned int whiteLightMap; 264 unsigned char whiteTexture[3]; 265 void swapAllBspCoordinates(); 266 void swapCoords(int * array); 267 void swapCoords(float * array); 268 SDL_Surface* testSurf; 269 270 271 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 272 }; 273 -
branches/terrain/src/lib/graphics/importer/bsp_manager.cc
r9110 r9324 196 196 this->outputFraction = 1.0f; 197 197 198 if ( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0 ) //!< if (sizeof(Visdata) == 0) 198 if ( ( viscluster < 0 ) || 199 ( bspFile->header.lumps[Visdata].length == 0 ) ) //!< if (sizeof(Visdata) == 0) 199 200 { 200 201
Note: See TracChangeset
for help on using the changeset viewer.