Changeset 8741 in orxonox.OLD for branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
- Timestamp:
- Jun 23, 2006, 11:29:40 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
r8697 r8741 29 29 memcpy( heightfield.data, tmpData->pixels, sizeof(UByte)*dataSize ); 30 30 SDL_FreeSurface( tmpData ); 31 //TODO: Perform some checks... 31 //TODO: Perform some checks... size, bits and so on 32 32 pagesX = (heightfield.width/(pageSize-1) ); 33 33 pagesZ = (heightfield.height/(pageSize-1) ); 34 //tex = (Texture*)MANAGER->load( lightmapSource );35 34 //TODO: Determine layer visibility! 36 35 for ( unsigned int i = 0; i < materials.size(); ++i ) { 37 36 38 37 } 39 40 printf( " * creating terrain pages ( %d, %d )...", pagesX, pagesZ );41 38 pages = new pTerrainPage[pagesX*pagesZ]; 42 39 for ( int x = 0; x < pagesX; ++x ) 43 40 for ( int z = 0; z < pagesZ; ++z ) 44 41 pages[z*pagesX+x] = createPage( x, z ); 45 printf( "looks good\n" );46 printf( " * inform pages about the adjacent pages..." );47 42 //Inform each page about its neighbors. 48 43 for ( int x = 0; x < pagesX; ++x ) … … 54 49 z > 0 ? getPage( x+0, z-1 ) : NULL ); 55 50 56 printf( "looks good\n" );57 printf( " * creating quad_tree data structure..." );58 51 root = createQuadTree( 0, 0, pagesX, pagesZ ); 59 52 activePages = NULL; 60 printf( "looks good\n" );61 53 } 62 54 … … 104 96 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 105 97 indices, GL_DYNAMIC_DRAW_ARB ); 106 //printf( "uploaded %d verts and %d indices\n", bi.numIndices, bi.numVertices );107 98 BufferInfo newInfo; 108 99 broker->acquire( newInfo.vbIdentifier, newInfo.ibIdentifier ); … … 114 105 memcpy( &vertices[bi.numVertices], _vertices, 115 106 _numVertices*sizeof( Vertex ) ); 116 bi.numVertices+=_numVertices;117 107 //The indices need to be updated with an offset :( 118 unsigned short *end = _indices+_numIndices; 119 unsigned short *dst = indices+bi.numIndices; 120 int offset = bi.numIndices; 121 if ( bi.numIndices > 0 ) { 122 indices[bi.numIndices] = indices[bi.numIndices-1]; 123 indices[bi.numIndices+1] = _indices[0]+offset; 124 dst+=2; 125 bi.numIndices+=2; 126 } 127 for ( unsigned short *i = _indices; i < end; ++i, ++dst ) { 128 *dst = *i+offset; 108 unsigned short *dst= &indices[bi.numIndices]; 109 unsigned short offset = bi.numVertices; 110 unsigned short *src= _indices; 111 unsigned short *end= src+_numIndices; 112 bi.numVertices+=_numVertices; 113 if ( bi.numIndices ) { 114 dst[0] = *(dst-1); 115 dst[1] = *src+offset; 116 dst+=2; bi.numIndices+=2; 117 } 118 while ( src < end ) { 119 *dst= *src+offset; 120 dst++; 121 src++; 129 122 } 130 123 bi.numIndices+=_numIndices; … … 167 160 frustum->extractPlanes(); 168 161 169 /* *162 /* 170 163 * Enable texture and vertex arrays for the first and the second texture 171 164 * units and disable the normal arrays. … … 181 174 glDisableClientState( GL_NORMAL_ARRAY ); 182 175 glDisable( GL_CULL_FACE ); 176 glCullFace( GL_BACK ); 183 177 glDisable( GL_LIGHTING ); 184 178 glColor3f( 1.0f, 1.0f, 1.0f ); … … 230 224 page = activePages; 231 225 while ( page ) { 226 assert( page->isActive() ); 232 227 page->updateTesselation(); 233 228 page = page->getNext(); … … 236 231 if ( buffers[current].numIndices != 0 ) { 237 232 BufferInfo bi = buffers[current]; 238 glBindBufferARB( GL_ARRAY_BUFFER_ARB, 239 bi.vbIdentifier ); 233 glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier ); 240 234 glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ), 241 235 vertices, GL_DYNAMIC_DRAW_ARB ); 242 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 243 bi.ibIdentifier ); 236 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier ); 244 237 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 245 238 indices, GL_DYNAMIC_DRAW_ARB ); 246 239 } 247 s = 200.0f;248 240 glPushAttrib( GL_COLOR_BUFFER_BIT ); 249 241 for ( unsigned int i = 0; i < materials.size(); ++i ) { … … 258 250 glMatrixMode( GL_TEXTURE ); 259 251 glLoadIdentity(); 260 glScalef( s, s, s);252 glScalef( pagesX, pagesZ, 1.0f ); 261 253 262 254 glClientActiveTextureARB( GL_TEXTURE0_ARB ); … … 264 256 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 265 257 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 258 glEnable( GL_CULL_FACE ); 266 259 for ( unsigned j = 0; j < buffers.size(); ++j ) { 267 260 BufferInfo bi = buffers[j];
Note: See TracChangeset
for help on using the changeset viewer.