Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 23, 2006, 11:29:40 AM (18 years ago)
Author:
ponder
Message:
  • Finally, I got the terrain working completly. What a hard work… It took me lots and lots of hours to remove all bugs in the tesselation routines.
File:
1 edited

Legend:

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

    r8697 r8741  
    2929        memcpy( heightfield.data, tmpData->pixels, sizeof(UByte)*dataSize );
    3030        SDL_FreeSurface( tmpData );
    31         //TODO: Perform some checks...
     31        //TODO: Perform some checks... size, bits and so on
    3232        pagesX = (heightfield.width/(pageSize-1) );
    3333        pagesZ = (heightfield.height/(pageSize-1) );
    34         //tex = (Texture*)MANAGER->load( lightmapSource );
    3534        //TODO: Determine layer visibility!     
    3635        for ( unsigned int i = 0; i < materials.size(); ++i ) {
    3736               
    3837        }
    39 
    40         printf( " * creating terrain pages ( %d, %d )...", pagesX, pagesZ );
    4138        pages = new pTerrainPage[pagesX*pagesZ];       
    4239        for ( int x = 0; x < pagesX; ++x )
    4340                for ( int z = 0; z < pagesZ; ++z )
    4441                        pages[z*pagesX+x] = createPage( x, z );
    45         printf( "looks good\n" );
    46         printf( " * inform pages about the adjacent pages..." );                       
    4742        //Inform each page about its neighbors.
    4843        for ( int x = 0; x < pagesX; ++x )
     
    5449                                z > 0                   ? getPage( x+0, z-1 ) : NULL );
    5550       
    56         printf( "looks good\n" );
    57         printf( " * creating quad_tree data structure..." );
    5851        root = createQuadTree( 0, 0, pagesX, pagesZ );
    5952        activePages = NULL;
    60         printf( "looks good\n" );
    6153}
    6254
     
    10496                glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ),
    10597                        indices, GL_DYNAMIC_DRAW_ARB );
    106                 //printf( "uploaded %d verts and %d indices\n", bi.numIndices, bi.numVertices );
    10798                BufferInfo newInfo;
    10899                broker->acquire( newInfo.vbIdentifier, newInfo.ibIdentifier );                 
     
    114105        memcpy( &vertices[bi.numVertices], _vertices,
    115106                _numVertices*sizeof( Vertex ) );
    116         bi.numVertices+=_numVertices;
    117107        //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++;
    129122        }
    130123        bi.numIndices+=_numIndices;
     
    167160        frustum->extractPlanes();
    168161       
    169         /**
     162        /*
    170163         * Enable texture and vertex arrays for the first and the second texture
    171164         * units and disable the normal arrays.
     
    181174                glDisableClientState( GL_NORMAL_ARRAY );
    182175        glDisable( GL_CULL_FACE );
     176        glCullFace( GL_BACK );
    183177        glDisable( GL_LIGHTING );
    184178        glColor3f( 1.0f, 1.0f, 1.0f );
     
    230224        page = activePages;
    231225        while ( page ) {
     226                assert( page->isActive() );
    232227                page->updateTesselation();
    233228                page = page->getNext();
     
    236231        if ( buffers[current].numIndices != 0 ) {
    237232                BufferInfo bi = buffers[current];       
    238                 glBindBufferARB( GL_ARRAY_BUFFER_ARB,
    239                         bi.vbIdentifier );
     233                glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier );
    240234                glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ),
    241235                        vertices, GL_DYNAMIC_DRAW_ARB );
    242                 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB,
    243                         bi.ibIdentifier );
     236                glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier );
    244237                glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ),
    245238                        indices, GL_DYNAMIC_DRAW_ARB );
    246239        }
    247         s = 200.0f;
    248240        glPushAttrib( GL_COLOR_BUFFER_BIT );
    249241        for ( unsigned int i = 0; i < materials.size(); ++i ) {
     
    258250                glMatrixMode( GL_TEXTURE );
    259251                glLoadIdentity();
    260                 glScalef( s, s, s );
     252                glScalef( pagesX, pagesZ, 1.0f );
    261253
    262254                glClientActiveTextureARB( GL_TEXTURE0_ARB );
     
    264256                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );                         
    265257                glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
     258                glEnable( GL_CULL_FACE );
    266259                for ( unsigned j = 0; j < buffers.size(); ++j ) {
    267260                        BufferInfo bi = buffers[j];
Note: See TracChangeset for help on using the changeset viewer.