Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9414 in orxonox.OLD for branches/terrain


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

merged back here the terrain.old

Location:
branches/terrain/src
Files:
2 deleted
15 edited
17 copied

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/effects/volfog_effect.cc

    r9406 r9414  
    3030//#include <GL/glext.h> //OpenGL Extensions
    3131//#include <GL/glxext.h> // GLX Extensions
    32 
     32#ifndef __APPLE__
    3333#ifndef GL_EXT_fog_coord
    3434#define GL_EXT_fog_coord 1
     
    4545PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT = 0;
    4646PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT = 0;
    47 
     47#endif
    4848
    4949
  • branches/terrain/src/lib/graphics/graphics_engine.cc

    r9406 r9414  
    240240  // Enable default GL stuff
    241241  glEnable(GL_DEPTH_TEST);
    242 
     242  glEnable(GL_CULL_FACE);
     243  glCullFace(GL_FRONT);
    243244  Render2D::getInstance();
    244245
     
    301302  }
    302303
    303   glEnable(GL_CULL_FACE);
    304   glCullFace(GL_FRONT);
     304
    305305}
    306306
  • branches/terrain/src/lib/graphics/importer/Makefile.am

    r8724 r9414  
    3838                           md3/md3_mesh.cc \
    3939                           md3/md3_data.cc \
    40                            md3/md3_tag.cc
    41 
    42 
     40                           md3/md3_tag.cc \
     41                           \
     42                           terrain/terrain.cc \
     43                           terrain/terrain_quad.cc \
     44                           terrain/terrain_page.cc \
     45                           terrain/frustum.cc \
     46                           terrain/buffer_broker.cc
    4347
    4448
     
    8185                md3/md3_mesh.h \
    8286                md3/md3_data.h \
    83                 md3/md3_tag.h
     87                md3/md3_tag.h \
     88                \
     89                terrain/terrain.h \
     90                terrain/terrain_page.h \
     91                terrain/terrain_quad.h \
     92                terrain/frustum.h \
     93                terrain/types.h \
     94                terrain/buffer_broker.h
    8495
  • 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++)
  • branches/terrain/src/lib/graphics/importer/bsp_file.h

    r9003 r9414  
    1919
    2020#include <vector>
     21#include "filesys/binary_file.h"
    2122class SDL_Surface;
    2223class BspTreeNode;
     
    2728
    2829
    29  struct plane
     30struct bsp_lump {
     31        int                     offset;
     32        int                     length;
     33};
     34
     35enum 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
     55struct 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
     63struct plane
    3064{
    3165  float x;     //!< 1st component of the plane's normal
     
    3468  float d;     //!< distance of the plane to the origin
    3569};
     70
    3671
    3772typedef struct
     
    82117}
    83118brushside;
     119
    84120
    85121struct face
     
    101137} ;
    102138
     139
    103140typedef struct
    104141{
     
    130167}
    131168AMat;
    132 
    133169typedef struct
    134170{
     
    144180}
    145181BspTexture;
     182
    146183
    147184class BspFile
     
    162199
    163200private:
    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

    r9235 r9414  
    199199  this->outputFraction = 1.0f;
    200200
    201   if ( viscluster < 0  || ((int *)(this->bspFile->header))[35] == 0 )  //!< if (sizeof(Visdata) == 0)
     201  if ( ( viscluster < 0  ) ||
     202                ( bspFile->header.lumps[Visdata].length == 0 ) )  //!< if (sizeof(Visdata) == 0)
    202203  {
    203204
  • branches/terrain/src/lib/graphics/importer/md2/md2Model.cc

    r9406 r9414  
    1717#include "md2Model.h"
    1818#include "material.h"
    19 
     19#include "config.h"
     20#ifdef HAVE_SDL_SDL_H
     21#include <SDL/SDL.h>
     22#include <SDL/SDL_endian.h>
     23#else
     24#include <SDL.h>
     25#include <SDL_endian.h>
     26#endif
    2027#include "debug.h"
    2128#include "util/loading/resource_manager.h"
     
    6774  };
    6875
    69 
     76#ifdef SDL_LIL_ENDIAN
     77#define BULK_CONV( _ptr, _num ) do { \
     78        int  _cnt = _num;\
     79        int* _iptr = (int*)_ptr;\
     80        for( int _l = 0; _l<_cnt; ++_l )\
     81                _iptr[_l] = SDL_SwapLE32( _iptr[_l] );\
     82} while( 0 )
     83#define BULK_CONV16( _ptr, _num ) do { \
     84        short  _cnt = _num;\
     85        short* _iptr = (short*)_ptr;\
     86        for( int _l = 0; _l<_cnt; ++_l )\
     87                _iptr[_l] = SDL_SwapLE16( _iptr[_l] );\
     88} while( 0 )
     89#else
     90#define BULK_CONV( _ptr, _num )
     91#define BULK_CONV16( _ptr, _num )
     92#endif
    7093
    7194/********************************************************************************
     
    468491  this->header = new MD2Header;
    469492  fread(this->header, 1, sizeof(MD2Header), pFile);
     493        BULK_CONV( this->header, sizeof(MD2Header)/4 );
    470494  /* check for the header version: make sure its a md2 file :) */
    471   if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
     495  if( unlikely( this->header->version != MD2_VERSION) && unlikely( this->header->ident != MD2_IDENT))
    472496    {
    473497      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     
    475499    }
    476500
    477   this->fileName =fileName;
     501  this->fileName = fileName;
    478502  /* got the data: map it to locals */
    479503  this->numFrames = this->header->numFrames;
     
    494518  fseek(pFile, this->header->offsetFrames, SEEK_SET);
    495519  fread(buffer, this->header->frameSize, this->numFrames, pFile);
     520        //BULK_CONV( buffer, this->header->frameSize*this->numFrames*sizeof(char)/4 );
    496521  /* read opengl commands */
    497522  fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
     523
    498524  fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
     525        BULK_CONV( this->pGLCommands, this->numGLCommands );
    499526  /* triangle list */
    500527  fseek(pFile, this->header->offsetTriangles, SEEK_SET);
    501   fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
     528  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);       
     529        BULK_CONV16( this->pTriangles, this->numTriangles*sizeof(sTriangle)/2 );
     530
    502531  /*  read in texture coordinates */
    503532  fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
    504533  fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
    505 
     534        BULK_CONV16( this->pTexCoor, this->numTexCoor*sizeof(sTexCoor)/2 );
    506535
    507536  for(int i = 0; i < this->numFrames; ++i)
    508537    {
    509538      frame = (sFrame*)(buffer + this->header->frameSize * i);
     539                        //Convert the translate and scale Vec3D if needed.
     540                        BULK_CONV( frame, 6 );
     541                        BULK_CONV( frame->pVertices, 3 );
    510542      pVertex = this->pVertices + this->numVertices  * i;
    511543      pNormals = this->pLightNormals + this->numVertices * i;
  • branches/terrain/src/lib/graphics/importer/md3/md3_animation_cfg.cc

    r9406 r9414  
    173173        }
    174174        }
    175     }
     175    }*/
    176176      */
    177177  }
  • branches/terrain/src/lib/graphics/importer/md3/md3_data.h

    r8724 r9414  
    7070  };
    7171
    72 
    7372  //! class to store the md2 data in
    7473  class MD3Data : public BaseObject
  • branches/terrain/src/lib/sound/ogg_player.cc

    r9406 r9414  
    402402    if(size == 0)
    403403      return false;
    404 /*#ifdef SDL_BIG_ENDIAN
    405                         int cnt = wavLength/2;
    406                         Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer;
    407                         for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )
    408                                 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );
    409 #endif*/
     404#ifdef SDL_BIG_ENDIAN
     405        int cnt = OGG_PLAYER_BUFFER_SIZE/2;
     406        Uint16* wavBufferAsShorts = ( Uint16* )pcm;
     407        for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )
     408                *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );
     409#endif
    410410    alBufferData(buffer, format, pcm, size, vorbisInfo->rate);
    411411    if (DEBUG_LEVEL >= 3)
  • branches/terrain/src/lib/util/Makefile.am

    r9406 r9414  
    2323                filesys/file.cc \
    2424                filesys/directory.cc \
     25                filesys/binary_file.cc \
    2526                filesys/net_link.cc \
    2627                \
     
    4041                executor/executor_lua.h \
    4142                executor/functor_list.h \
     43                byte_order.h \
    4244                \
    4345                filesys/file.h \
    4446                filesys/directory.h \
     47                filesys/binary_file.h \
    4548                filesys/net_link.h \
    4649                \
  • branches/terrain/src/lib/util/filesys/file.cc

    r8619 r9414  
    155155}
    156156
    157 bool File::open(OpenMode mode)
    158 {
    159 #warning implement
    160   return false;
     157bool File::open( OpenMode mode )
     158{
     159   static const char* openModeStrings[] = {
     160                        "r", "w", "r+", "a+" };
     161        _mode = mode;
     162        _handle = fopen( name().c_str(), openModeStrings[mode] );
     163        return ( _handle != NULL );
    161164}
    162165
    163166bool File::close()
    164167{
    165 #warning implement
    166   return false;
     168        if ( _handle != NULL ) {
     169                int success = fclose( _handle );
     170                _handle = NULL;         
     171                return ( success == 0 );
     172        }
     173        return false;
    167174}
    168175
  • branches/terrain/src/lib/util/filesys/file.h

    r8619 r9414  
    1616  public:
    1717  //! How the File should be opened.
    18   typedef enum
    19   {
    20     ReadOnly,      //!< ReadOnly mode
    21     WriteOnly,     //!< WriteOnly mode
    22     ReadWrite,     //!< Read and Write mode together
    23     Append,        //!< Append at the end.
     18  typedef enum {
     19    ReadOnly    = 0,     //!< ReadOnly mode
     20    WriteOnly   = 1,     //!< WriteOnly mode
     21    ReadWrite   = 2,     //!< Read and Write mode together
     22    Append              = 3      //!< Append at the end.
    2423  } OpenMode;
    25 
    2624public:
    2725  File();
     
    4139  virtual bool open(OpenMode mode);
    4240  virtual bool close();
    43   int handle() const { return this->_handle; };
    44 
     41  FILE* handle() const
     42  { return this->_handle; };
     43  inline OpenMode mode() const
     44  { return _mode; }
    4545  /** @returns the FileName of this File */
    4646  const std::string& name() const { return this->_name; };
     
    7373
    7474  private:
    75     int                 _handle;          //!< The FileHandle (if set).
     75    FILE*               _handle;          //!< The FileHandle (if set).
    7676    std::string         _name;            //!< The Name of the File.
    7777    stat*               _status;          //!< The Stat of the File.
    78 
     78        OpenMode                        _mode;
    7979    static std::string  _cwd;             //!< The currend Working directory.
    8080
  • branches/terrain/src/world_entities/WorldEntities.am

    r9235 r9414  
    1515                world_entities/skybox.cc \
    1616                world_entities/skydome.cc \
    17                 world_entities/terrain.cc \
     17                world_entities/terrain_entity.cc \
    1818                world_entities/satellite.cc \
    1919                world_entities/movie_entity.cc \
     
    8787                skybox.h \
    8888                skydome.h \
    89                 terrain.h \
     89                terrain_entity.h \
    9090                satellite.h \
    9191                movie_entity.h \
  • branches/terrain/src/world_entities/skybox.cc

    r9406 r9414  
    230230//   glPushAttrib(GL_LIGHTING_BIT);
    231231  glDisable(GL_LIGHTING);
    232 
     232  glDisable( GL_DEPTH_TEST );   
    233233  glDisable(GL_FOG);
    234234
Note: See TracChangeset for help on using the changeset viewer.