Show
Ignore:
Timestamp:
10/10/09 11:53:10 (5 years ago)
Author:
robert
Message:

From Wojciech Lewandowski, "ref_ptr usage changes made on 9th of June broke VirtualProgram? used in osgShaderCompositor example. Taking the opportunity I modified the code a little to use earth sphere as default model. Cow.osg used previously was not looking good in advanced example. I also changed default to advanced example, because its more informative with labels describing virtual programs used to render the objects."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgshadercompositor/osgshadercompositor.cpp

    r10290 r10630  
    66#include <osgDB/ReadFile> 
    77#include <osgViewer/Viewer> 
     8#include <osg/ShapeDrawable> 
     9#include <osg/Material> 
    810 
    9 extern osg::Node * CreateSimpleHierarchy( const char * file ); 
    10 extern osg::Node * CreateAdvancedHierarchy( const char * file ); 
     11extern osg::Node * CreateSimpleHierarchy( osg::Node * model ); 
     12extern osg::Node * CreateAdvancedHierarchy( osg::Node * model ); 
    1113 
     14//////////////////////////////////////////////////////////////////////////////// 
     15osg::Node * CreateGlobe( void ) 
     16{ 
     17    // File not found - create textured sphere  
     18    osg::Geode * geode = new osg::Geode; 
     19    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; 
     20    hints->setDetailRatio( 0.3 ); 
     21 
     22#if 1 
     23    osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable 
     24        ( new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 4.0 ), hints.get() ); 
     25#else 
     26    osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable 
     27        ( new osg::Box( osg::Vec3(-1.0f, -1.0f, -1.0f), 2.0, 2.0, 2.0 ) ); 
     28#endif 
     29 
     30    shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f)); 
     31 
     32    geode->addDrawable( shape.get() ); 
     33 
     34    osg::StateSet * stateSet = new osg::StateSet; 
     35 
     36    osg::Texture2D * texture =  new osg::Texture2D(  
     37        osgDB::readImageFile("Images/land_shallow_topo_2048.jpg")  
     38    ); 
     39 
     40    osg::Material * material = new osg::Material; 
     41 
     42    material->setAmbient 
     43        ( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.9, 0.9, 0.9, 1.0 ) ); 
     44 
     45    material->setDiffuse 
     46        ( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.9, 0.9, 0.9, 1.0 ) ); 
     47 
     48#if 1 
     49    material->setSpecular 
     50        ( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.7, 0.3, 0.3, 1.0 ) ); 
     51 
     52    material->setShininess( osg::Material::FRONT_AND_BACK, 25 ); 
     53 
     54#endif 
     55 
     56    stateSet->setAttributeAndModes( material ); 
     57    stateSet->setTextureAttributeAndModes( 0,texture, osg::StateAttribute::ON ); 
     58 
     59    geode->setStateSet( stateSet ); 
     60    return geode; 
     61} 
     62//////////////////////////////////////////////////////////////////////////////// 
    1263int main( int argc, char **argv ) 
    1364{ 
     
    1667    osgViewer::Viewer viewer( arguments ); 
    1768 
    18     std::string filename = "cow.osg"; 
    19     bool useAdvancedTechnique = arguments.read("-a") || arguments.read("--advanced") ; 
     69    bool useSimpleExample = arguments.read("-s") || arguments.read("--simple") ; 
    2070 
    21     if (arguments.argc()>1) 
    22     { 
    23         if (!arguments.isOption(1)) filename =  arguments[1]; 
     71    osg::Node * model = NULL; 
     72 
     73    if (arguments.argc()>1 && !arguments.isOption(1) ) { 
     74        std::string filename = arguments[1]; 
     75        model = osgDB::readNodeFile( filename ); 
     76        if ( !model ) { 
     77            osg::notify( osg::NOTICE )  
     78                << "Error, cannot read " << filename  
     79                << ". Loading default earth model instead." << std::endl; 
     80        } 
    2481    } 
    2582 
    26     // osg::Node * node = CreateSimpleHierarchy( file ); 
    27     osg::Node * node = useAdvancedTechnique ? 
    28         CreateAdvancedHierarchy( filename.c_str() ) : 
    29         CreateSimpleHierarchy( filename.c_str() ); 
     83    if( model == NULL ) 
     84        model = CreateGlobe( ); 
    3085 
    31     if ( !node ) { 
    32         osg::notify( osg::NOTICE ) << "Error, cannot read " << filename << std::endl; 
    33         return 1; 
    34     }     
     86    osg::Node * node = useSimpleExample ?         
     87        CreateSimpleHierarchy( model ): 
     88        CreateAdvancedHierarchy( model ); 
    3589 
    3690    viewer.setSceneData( node );