Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 24, 2006, 12:47:07 PM (18 years ago)
Author:
bensch
Message:

merged back here the terrain.old

File:
1 edited

Legend:

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

    r9406 r9414  
    2121#include "bsp_file.h"
    2222#include "bsp_tree_node.h"
    23 #include <fstream>
    2423#include "util/loading/resource_manager.h"
    25 
     24#include <string>
    2625#include <sys/stat.h>
    2726#include <string.h>
     27#include "filesys/binary_file.h"
    2828#include "debug.h"
    2929#include "material.h"
     
    4040#include <vector>
    4141
    42 
    43 
     42using namespace std;
     43
     44static const char* HEADER_SEMANTICS             = "b4i35";
     45static const char* NODE_SEMANTICS                       = "i9";
     46static const char* LEAF_SEMANTICS                       = "i12";
     47static const char* MODEL_SEMANTICS                      = "i10";
     48static const char* BRUSH_SEMANTICS              = "i3";
     49static const char* BRUSHSIDE_SEMANTICS          = "i2";
     50static const char* FACE_SEMANTICS                       = "i26";
     51static const char* VERTEX_SEMANTICS             = "i10b4";
     52static const char* LIGHTMAP_SEMANTICS           = "b49152";
     53static const char* TEXTURE_SEMANTICS            = "b64i2";
     54static const char* PLANE_SEMANTICS                      = "f4";
    4455
    4556// Constructor
     
    8192
    8293}
    83 
     94void BspFile::readEntities()
     95{
     96        /* We do nothing here */
     97}
     98void 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}
     108void 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
     119void 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
     130void 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
     141void 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
     152void 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
     163void 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
     174void 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}
     184void 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
     195void 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
     205void BspFile::readEffects()
     206{
     207        /* not loaded atm */
     208}
     209
     210void 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
     221void 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}
     231void BspFile::readLightvols()
     232{
     233        /* not loaded atm */   
     234}
     235void 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}
     246void 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}
    84256/**
    85257 *  Loads a quake3 level (*.bsp)
     
    88260int BspFile::read(const char* name)
    89261{
    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     std::ifstream bspFile (name, std::ios::in | std::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        }
    355369}
    356370
     
    430444  char fileName [500];
    431445  char ext [500];
    432   struct stat results;
     446  //struct stat results;
    433447
    434448
     
    660674  int      errorCode = 0;           //!< the error code for the texture loading functions
    661675  unsigned int   lightMap;          //!< the OpenGL texture handle
    662   int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
     676 /* int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
    663677  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*/
    665679  float sc, scale, temp;
    666680  for(int i = 0; i < 128*128*3 ; i++)
Note: See TracChangeset for help on using the changeset viewer.