Changeset 8744 in orxonox.OLD for branches/terrain/src/lib/graphics/importer
- Timestamp:
- Jun 23, 2006, 3:22:53 PM (18 years ago)
- Location:
- branches/terrain/src/lib/graphics/importer/terrain
- Files:
-
- 3 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" );
Note: See TracChangeset
for help on using the changeset viewer.