Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8744 in orxonox.OLD


Ignore:
Timestamp:
Jun 23, 2006, 3:22:53 PM (18 years ago)
Author:
ponder
Message:
  • A few more properties can be specified in the .oxw file for the terrain.
  • several material-layers can be rendered now.
  • there is still one crack appearing now and then.. need to isolate it and send him to hell.
Location:
branches/terrain/src
Files:
4 edited

Legend:

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

    r8741 r8744  
    3232        pagesX = (heightfield.width/(pageSize-1) );
    3333        pagesZ = (heightfield.height/(pageSize-1) );
     34       
    3435        //TODO: Determine layer visibility!     
    35         for ( unsigned int i = 0; i < materials.size(); ++i ) {
    36                
    37         }
     36        for ( unsigned int i = 0; i < layers.size(); ++i ) {
     37               
     38        }
     39       
    3840        pages = new pTerrainPage[pagesX*pagesZ];       
    3941        for ( int x = 0; x < pagesX; ++x )
     
    155157void Terrain::draw( )
    156158{
    157         static float s = 0.0f;
    158159        glGetError();
    159160        pTerrainPage page = NULL;
     
    228229                page = page->getNext();
    229230        }
    230         //Finish the last buffer
     231        //If there is some data in the buffer, we need to upload the data
     232        //into the vram...
    231233        if ( buffers[current].numIndices != 0 ) {
    232234                BufferInfo bi = buffers[current];       
     
    239241        }
    240242        glPushAttrib( GL_COLOR_BUFFER_BIT );
    241         for ( unsigned int i = 0; i < materials.size(); ++i ) {
     243        glEnable( GL_BLEND );
     244        glDepthFunc( GL_LEQUAL );
     245        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
     246        for ( unsigned int i = 0; i < layers.size(); ++i ) {
     247                LayerInfo* layer= layers[i];
    242248                page = activePages;     
    243                
    244                 //This is a hack! Remove this as soon as possible
    245                 materials[i]->unselect();
    246                 materials[i]->select();
    247                
     249                               
    248250                glActiveTextureARB( GL_TEXTURE1_ARB );
    249251                glClientActiveTextureARB( GL_TEXTURE1_ARB );
    250                 glMatrixMode( GL_TEXTURE );
    251                 glLoadIdentity();
    252                 glScalef( pagesX, pagesZ, 1.0f );
     252                if ( layer->detail ) {
     253                        //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );
     254                        glEnable( GL_TEXTURE_2D );
     255                        glBindTexture( GL_TEXTURE_2D, layer->detail->getTexture() );
     256                        glMatrixMode( GL_TEXTURE );
     257                        glLoadIdentity();
     258                        glScalef( layer->repeatX, layer->repeatZ, 1.0f );
     259                }       
     260                else {
     261                        glDisable( GL_TEXTURE_2D );
     262                }
    253263
    254264                glClientActiveTextureARB( GL_TEXTURE0_ARB );
    255265                glActiveTextureARB( GL_TEXTURE0_ARB );
     266                glEnable( GL_TEXTURE_2D );
     267                if ( layer->alpha ) {
     268                        //glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND );                   
     269                        glBindTexture( GL_TEXTURE_2D, layer->alpha->getTexture() );
     270                }
     271                else {
     272               
     273                        glBindTexture( GL_TEXTURE_2D, lightmap->getTexture() );                 
     274                }
    256275                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );                         
    257276                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
     
    280299        }
    281300       
    282         //Get rid of the buffers
    283        
    284301        for ( unsigned int i = 0; i < buffers.size(); ++i )
    285302                broker->release( buffers[i].vbIdentifier, buffers[i].ibIdentifier );
     303               
    286304        buffers.clear();
    287305               
    288306        glClientActiveTextureARB( GL_TEXTURE1_ARB );   
     307        glActiveTextureARB( GL_TEXTURE1_ARB );
     308        glDisable( GL_TEXTURE_2D );
    289309        glDisableClientState( GL_VERTEX_ARRAY );
    290310        glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    291311        glDisableClientState( GL_VERTEX_ARRAY );
    292312        glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    293         materials[0]->unselect();
    294313        glActiveTextureARB( GL_TEXTURE0_ARB );
    295314        glClientActiveTextureARB( GL_TEXTURE0_ARB );   
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.h

    r8741 r8744  
    2626#include <cstdlib>
    2727#include <string>
    28 #include <list>
    29 #include "material.h"
     28#include <vector>
    3029#include "texture.h"
    3130#include "frustum.h"
    3231
    33 
    34 typedef struct {
     32class Terrain;
     33typedef Terrain *pTerrain;
     34       
     35struct Heightfield {
    3536        int                     width;
    3637        int                     height;
    3738        int                             pitch;
    3839        UByte                   *data;
    39 } Heightfield, *pHeightfield;
     40};
     41
     42struct LayerInfo {
     43
     44        int                             envmode;
     45        float                   repeatX,
     46                                        repeatZ;
     47        Texture                 *alpha;
     48        Texture                 *detail;
     49       
     50};
    4051
    4152struct BufferInfo {
    42        
    43         unsigned int    vbIdentifier,
    44                                         ibIdentifier,
    45                                         numIndices,
    46                                         numVertices;
    4753       
    4854        BufferInfo( unsigned int _vb, unsigned int _ib,
     
    5864                vbIdentifier = ibIdentifier = numIndices = numVertices = 0;
    5965        }
    60 };
    61 
    62 
    63 class Terrain;
    64 
    65 typedef Terrain *pTerrain;
    66 
    67 class TerrainPage;
     66        unsigned int    vbIdentifier,
     67                                        ibIdentifier,
     68                                        numIndices,
     69                                        numVertices;   
     70};
     71
    6872
    6973class Terrain {
     
    99103                void getAltitude( Triple& _alt, Triple& _normal );
    100104               
     105                inline void setLightmap( Texture *_lightmap )
     106                {
     107                        lightmap = _lightmap;
     108                }
    101109                //What a bad name: Need to rename that :(
    102110                void addLevelFourPage( int _numVertices, Vertex *_vertices,
     
    147155                inline float getAltitude( int _x, int _z ) const;
    148156               
    149                 inline void addMaterial( Material *_material )
    150                 {
    151                         materials.push_back( _material );
    152                 }
    153                
    154                 /*inline void setLightmap( const std::string &_lightmap )
    155                 {
    156                         lightmapSource = _lightmap;
    157                 }*/
     157                inline void addMaterialLayer( LayerInfo *_layer )
     158                { layers.push_back( _layer ); }
     159               
    158160                inline void setHeightmap( const std::string &_heightmap )
    159161                {
     
    215217                pTerrainPage                            *pages;         // the references to all pages
    216218                std::string                                     heightmapSource;
    217                 std::string                                     lightmapSource;
     219                Texture                                         *lightmap;
    218220                Heightfield                                     heightfield;
    219221                Triple                                          scale;
     
    236238                pFrustum                                        frustum;
    237239                pTerrainPage                            activePages;
    238                 std::vector<Material*>          materials;
     240                std::vector<LayerInfo*>         layers;
    239241};
    240242
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc

    r8741 r8744  
    713713               
    714714        assert( isVisible ); assert( numIndices > 0 );
    715         assert( active );
    716715        active = false;
    717716        CHECK_GL_ERROR( "1" ); 
  • branches/terrain/src/world_entities/terrain_entity.cc

    r8741 r8744  
    115115void TerrainEntity::loadParams(const TiXmlElement* root)
    116116{
    117         WorldEntity::loadParams(root);
     117        WorldEntity::loadParams( root );
    118118
    119119        LoadParam(root, "scale", this, TerrainEntity, setScale)
    120120                .describe("The scale in x,y,z direction");
    121121       
    122         LoadParam( root, "lightmap", this, TerrainEntity, loadLightmap )
     122        LoadParam( root, "light_map", this, TerrainEntity, loadLightmap )
    123123                .describe("The name of the lightmap.");
    124124               
    125         LoadParam( root, "elevationmap", this, TerrainEntity, loadElevationmap )
     125        LoadParam( root, "elevation_map", this, TerrainEntity, loadElevationmap )
    126126                .describe( "The name of the elevation map. Must be an 8bit image" );
    127                
     127        ResourceManager *manager = ResourceManager::getInstance();
     128        TiXmlElement * layer = (TiXmlElement*)root->FirstChild( "material_layer" );             
     129        while ( layer ) {
     130                LayerInfo *info = new LayerInfo();
     131                TiXmlElement *detail = (TiXmlElement*)layer->FirstChild( "detail_map" );
     132                if ( detail ) {
     133                        string detailmap( detail->Attribute( "file" ) );
     134                        info->detail = (Texture*)manager->load( detailmap,
     135                                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );                   
     136                        if ( !info->detail ) {
     137                                PRINTF(0)( "%s not found\n", detailmap.c_str() );
     138                        }       
     139                        TiXmlElement *repeat = (TiXmlElement*)detail->FirstChild( "repeat" );
     140                        if ( repeat ) {
     141                                repeat->QueryFloatAttribute( "x", &info->repeatX );
     142                                repeat->QueryFloatAttribute( "z", &info->repeatZ );                             
     143                        }
     144                }
     145                else {
     146                        PRINTF(0)( "Please specify a detail-map" );
     147                }
     148                TiXmlElement *alpha = (TiXmlElement*)layer->FirstChild( "alpha" );
     149                if ( alpha ) {
     150                                if ( !alpha->Attribute( "full" ) ) {
     151                                        string alphamap( alpha->Attribute( "file" ) );
     152                                        info->alpha = (Texture*)manager->load( alphamap,
     153                                                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );
     154                                }
     155                }       
     156                terrain->addMaterialLayer( info );
     157                layer = (TiXmlElement*)layer->NextSibling( "material_layer" );
     158        }
    128159}
    129160
     
    140171void TerrainEntity::loadLightmap( const std::string& _lightFile )
    141172{
    142         Material *mat = new Material( "TERR_LM" );
    143         mat->setDiffuse( 1.0f, 1.0f, 1.0f );
    144         mat->setAmbient( 1.0f, 1.0f, 1.0f );
    145         mat->setDiffuseMap( _lightFile, GL_TEXTURE_2D, 0 );     
    146         mat->setDiffuseMap( std::string( "pictures/debug.png" ), GL_TEXTURE_2D, 1 );   
    147         terrain->addMaterial( mat );
     173        ResourceManager *manager = ResourceManager::getInstance();
     174        Texture *lightmap = (Texture*)manager->load( _lightFile,
     175                IMAGE, RP_GAME, (int)GL_TEXTURE_2D );   
     176        if ( lightmap )
     177                terrain->setLightmap( lightmap );
     178        else
     179                PRINTF(0)("no lightmap %s\n", _lightFile.c_str() );
    148180}
    149181
     
    173205        glPushMatrix();
    174206
    175   /* translate */
    176207   glTranslatef( this->getAbsCoor().x,
    177208                 this->getAbsCoor().y,
     
    184215                terrain->draw( );
    185216        }
    186 
    187217        glPopMatrix();
    188   /*
    189     glMatrixMode(GL_MODELVIEW);
    190     glPushMatrix();
    191     glLoadIdentity();
    192     Vector camera =   State::getCameraNode()->getAbsCoor(); // Go on here ..........!!!
    193 
    194     float height =    heightMap->getHeight(camera.x, camera.z);
    195 
    196     glEnable (GL_COLOR_MATERIAL) ;
    197     glBegin(GL_QUADS);            // Draw The Cube Using quads
    198     glColor3f(0.0f,1.0f,0.0f);  // Color Blue
    199     glVertex3f(camera.x + 63.0f,TerrainEntity->getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f);      // Top Right Of The Quad (Top)
    200     glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z-10.0f)+13.0f,camera.z-10.0f);      // Top Left Of The Quad (Top)
    201     glVertex3f(camera.x-63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f);      // Bottom Left Of The Quad (Top)
    202     glVertex3f(camera.x+ 63.0f, getHeight(camera.x+63.0f, camera.z+10.0f)+13.0f, camera.z+10.0f);      // Bottom Right Of The Quad (Top)
    203     glEnd();                      // End Drawing The Plan
    204 
    205     glPopMatrix();*/
     218
    206219
    207220}
Note: See TracChangeset for help on using the changeset viewer.