Changeset 8744 in orxonox.OLD for branches/terrain/src
- Timestamp:
- Jun 23, 2006, 3:22:53 PM (18 years ago)
- Location:
- branches/terrain/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8741 r8744 32 32 pagesX = (heightfield.width/(pageSize-1) ); 33 33 pagesZ = (heightfield.height/(pageSize-1) ); 34 34 35 //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 38 40 pages = new pTerrainPage[pagesX*pagesZ]; 39 41 for ( int x = 0; x < pagesX; ++x ) … … 155 157 void Terrain::draw( ) 156 158 { 157 static float s = 0.0f;158 159 glGetError(); 159 160 pTerrainPage page = NULL; … … 228 229 page = page->getNext(); 229 230 } 230 //Finish the last buffer 231 //If there is some data in the buffer, we need to upload the data 232 //into the vram... 231 233 if ( buffers[current].numIndices != 0 ) { 232 234 BufferInfo bi = buffers[current]; … … 239 241 } 240 242 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]; 242 248 page = activePages; 243 244 //This is a hack! Remove this as soon as possible 245 materials[i]->unselect(); 246 materials[i]->select(); 247 249 248 250 glActiveTextureARB( GL_TEXTURE1_ARB ); 249 251 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 } 253 263 254 264 glClientActiveTextureARB( GL_TEXTURE0_ARB ); 255 265 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 } 256 275 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 257 276 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); … … 280 299 } 281 300 282 //Get rid of the buffers283 284 301 for ( unsigned int i = 0; i < buffers.size(); ++i ) 285 302 broker->release( buffers[i].vbIdentifier, buffers[i].ibIdentifier ); 303 286 304 buffers.clear(); 287 305 288 306 glClientActiveTextureARB( GL_TEXTURE1_ARB ); 307 glActiveTextureARB( GL_TEXTURE1_ARB ); 308 glDisable( GL_TEXTURE_2D ); 289 309 glDisableClientState( GL_VERTEX_ARRAY ); 290 310 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 291 311 glDisableClientState( GL_VERTEX_ARRAY ); 292 312 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); 293 materials[0]->unselect();294 313 glActiveTextureARB( GL_TEXTURE0_ARB ); 295 314 glClientActiveTextureARB( GL_TEXTURE0_ARB ); -
branches/terrain/src/lib/graphics/importer/terrain/terrain.h
r8741 r8744 26 26 #include <cstdlib> 27 27 #include <string> 28 #include <list> 29 #include "material.h" 28 #include <vector> 30 29 #include "texture.h" 31 30 #include "frustum.h" 32 31 33 34 typedef struct { 32 class Terrain; 33 typedef Terrain *pTerrain; 34 35 struct Heightfield { 35 36 int width; 36 37 int height; 37 38 int pitch; 38 39 UByte *data; 39 } Heightfield, *pHeightfield; 40 }; 41 42 struct LayerInfo { 43 44 int envmode; 45 float repeatX, 46 repeatZ; 47 Texture *alpha; 48 Texture *detail; 49 50 }; 40 51 41 52 struct BufferInfo { 42 43 unsigned int vbIdentifier,44 ibIdentifier,45 numIndices,46 numVertices;47 53 48 54 BufferInfo( unsigned int _vb, unsigned int _ib, … … 58 64 vbIdentifier = ibIdentifier = numIndices = numVertices = 0; 59 65 } 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 68 72 69 73 class Terrain { … … 99 103 void getAltitude( Triple& _alt, Triple& _normal ); 100 104 105 inline void setLightmap( Texture *_lightmap ) 106 { 107 lightmap = _lightmap; 108 } 101 109 //What a bad name: Need to rename that :( 102 110 void addLevelFourPage( int _numVertices, Vertex *_vertices, … … 147 155 inline float getAltitude( int _x, int _z ) const; 148 156 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 158 160 inline void setHeightmap( const std::string &_heightmap ) 159 161 { … … 215 217 pTerrainPage *pages; // the references to all pages 216 218 std::string heightmapSource; 217 std::string lightmapSource;219 Texture *lightmap; 218 220 Heightfield heightfield; 219 221 Triple scale; … … 236 238 pFrustum frustum; 237 239 pTerrainPage activePages; 238 std::vector< Material*> materials;240 std::vector<LayerInfo*> layers; 239 241 }; 240 242 -
branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
r8741 r8744 713 713 714 714 assert( isVisible ); assert( numIndices > 0 ); 715 assert( active );716 715 active = false; 717 716 CHECK_GL_ERROR( "1" ); -
branches/terrain/src/world_entities/terrain_entity.cc
r8741 r8744 115 115 void TerrainEntity::loadParams(const TiXmlElement* root) 116 116 { 117 WorldEntity::loadParams( root);117 WorldEntity::loadParams( root ); 118 118 119 119 LoadParam(root, "scale", this, TerrainEntity, setScale) 120 120 .describe("The scale in x,y,z direction"); 121 121 122 LoadParam( root, "light map", this, TerrainEntity, loadLightmap )122 LoadParam( root, "light_map", this, TerrainEntity, loadLightmap ) 123 123 .describe("The name of the lightmap."); 124 124 125 LoadParam( root, "elevation map", this, TerrainEntity, loadElevationmap )125 LoadParam( root, "elevation_map", this, TerrainEntity, loadElevationmap ) 126 126 .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 } 128 159 } 129 160 … … 140 171 void TerrainEntity::loadLightmap( const std::string& _lightFile ) 141 172 { 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() ); 148 180 } 149 181 … … 173 205 glPushMatrix(); 174 206 175 /* translate */176 207 glTranslatef( this->getAbsCoor().x, 177 208 this->getAbsCoor().y, … … 184 215 terrain->draw( ); 185 216 } 186 187 217 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 206 219 207 220 }
Note: See TracChangeset
for help on using the changeset viewer.