Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 3, 2006, 10:23:35 PM (18 years ago)
Author:
ponder
Message:

Cleanup for the terrain

File:
1 edited

Legend:

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

    r8965 r9071  
    2828        SDL_Surface *tmpData = IMG_Load( full.c_str() );
    2929        if ( !tmpData ) {
    30                 PRINTF(0)( "I' sorry, I can't load %s\n", full.c_str() );
     30                PRINT(0)( "I' sorry, I can't load %s\n", full.c_str() );
    3131                return;
    3232        }               
    3333        if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) {
    34                 PRINTF(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
     34                PRINT(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
    3535                return;
    3636        }
    3737        if ( tmpData->format->BytesPerPixel != 1 ) {
    38                 PRINTF(0)( "The elevetation map must be an 8bit image!" );
     38                PRINT(0)( "The elevetation map must be an 8bit image not %d",
     39                        tmpData->format->BytesPerPixel*8 );
    3940                return;
    4041        }
     
    148149        switch( _node->cull() ) {
    149150                case Frustum::INTERSECT:
    150                         //printf( "partially inside frustum\n" );
    151151                        if ( !_node->isChildless() ) {
    152152                                pTerrainQuad *children = _node->getChildren();
     
    160160                        break;
    161161                case Frustum::INSIDE:
    162                         //printf( "fully inside frustum\n" );                   
    163162                        showPages( _node->getXOffset(),
    164163                                           _node->getZOffset(),
     
    167166                        break;
    168167                case Frustum::OUTSIDE:
    169                         cullCount+= (_node->getWidth()-1)*(_node->getHeight()-1);
    170168                        break;
    171169        }
     
    249247        //Due to some reason, the OpenGL implementors chose the plane equation
    250248        //to an array of doubles. So we will make them happy.
    251         double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };
    252         glEnable( GL_CLIP_PLANE0 );
    253         glClipPlane( GL_CLIP_PLANE0, farPlane );
     249        //double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };
     250        //glEnable( GL_CLIP_PLANE0 );
     251        //glClipPlane( GL_CLIP_PLANE0, farPlane );
    254252        glPushAttrib( GL_ALL_ATTRIB_BITS );
    255253        glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
     
    273271        //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
    274272        cullCount = 0;
    275        
    276         /*// Lets see which pages are visible.
    277         determineVisiblePages( root );
    278         int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD;
    279         pTerrainPage neighbor = NULL;
    280         page = activePages;
    281         bool dirty;
    282         current = 0;
    283         BufferInfo bi;
    284         broker->acquire( bi.vbIdentifier, bi.ibIdentifier );
    285         buffers.push_back( bi );
    286         int dirtyRounds = 0;
    287         do {
    288                 dirtyRounds++;
    289                 dirty = false;
    290                 page = activePages;
    291                 while ( page ) {
    292                         if ( !page->isActive() ) {
    293                                 pTerrainPage tmp = page;
    294                                 page = tmp->getNext();
    295                                 tmp->setVisibility( false );
    296                                 continue;
    297                         }
    298                         wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD();
    299                         if ( ( neighbor = page->getLeft() ) && ( neighbor->isActive() ) )
    300                                 wantedLeft = neighbor->getWantedLOD();
    301                         if ( ( neighbor = page->getRight() ) && ( neighbor->isActive() ) )
    302                                 wantedRight = neighbor->getWantedLOD();
    303                         if ( ( neighbor = page->getTop() ) && ( neighbor->isActive() ) )
    304                                 wantedTop = neighbor->getWantedLOD();
    305                         if ( ( neighbor = page->getBottom() ) && ( neighbor->isActive() ) )
    306                                 wantedBottom = neighbor->getWantedLOD();                       
    307                
    308                         minLOD = std::min( std::min( wantedBottom, wantedTop ),
    309                                 std::min( wantedLeft, wantedRight ) ); 
    310                         if ( minLOD < page->getWantedLOD()-1 ) {
    311                                 page->setWantedLOD( minLOD+1 );
    312                                 dirty = true;
    313                         }       
    314                         page = page->getNext();
    315                 }
    316         } while ( dirty );
    317        
    318         page = activePages;
    319         while ( page ) {
    320                 assert( page->isActive() );
    321                 page->updateTesselation();
    322                 page = page->getNext();
    323         }
    324         //If there is some data in the buffer, we need to upload the data
    325         //into the vram...
    326         if ( buffers[current].numIndices != 0 ) {
    327                 BufferInfo bi = buffers[current];       
    328                 glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier );
    329                 glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ),
    330                         vertices, GL_DYNAMIC_DRAW_ARB );
    331                 glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier );
    332                 glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ),
    333                         indices, GL_DYNAMIC_DRAW_ARB );
    334         }*/
    335273        glEnable( GL_BLEND );
    336274        glDepthFunc( GL_LEQUAL );
     
    389327                }
    390328        }
    391                        
    392329        glClientActiveTextureARB( GL_TEXTURE1_ARB );   
    393330        glActiveTextureARB( GL_TEXTURE1_ARB );
     
    412349                break;
    413350    case 2:
    414         pixel = *(Uint16 *)p;
     351                if ( SDL_BYTEORDER == SDL_BIG_ENDIAN )
     352                        pixel = p[0] << 8 | p[1];
     353                else
     354                pixel = *(Uint16 *)p;
    415355                break;
    416356    case 3:
     
    424364                break;
    425365    default:
    426         return 255;       /* shouldn't happen, but avoids warnings */
     366        return 255; /* shouldn't happen, but avoids warnings */
    427367    }
    428368        Uint8 r,g,b,a;
Note: See TracChangeset for help on using the changeset viewer.