/usr/share/openscenegraph/examples/osgvirtualprogram/osgvirtualprogram.cpp is in openscenegraph-examples 3.0.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <iostream>
#include <osg/Geode>
#include <osg/TexGen>
#include <osg/Texture2D>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/ShapeDrawable>
#include <osg/Material>
extern osg::Node * CreateSimpleHierarchy( osg::Node * model );
extern osg::Node * CreateAdvancedHierarchy( osg::Node * model );
////////////////////////////////////////////////////////////////////////////////
osg::Node * CreateGlobe( void )
{
// File not found - create textured sphere
osg::Geode * geode = new osg::Geode;
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
hints->setDetailRatio( 0.3 );
#if 1
osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable
( new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 4.0 ), hints.get() );
#else
osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable
( new osg::Box( osg::Vec3(-1.0f, -1.0f, -1.0f), 2.0, 2.0, 2.0 ) );
#endif
shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f));
geode->addDrawable( shape.get() );
osg::StateSet * stateSet = new osg::StateSet;
osg::Texture2D * texture = new osg::Texture2D(
osgDB::readImageFile("Images/land_shallow_topo_2048.jpg")
);
osg::Material * material = new osg::Material;
material->setAmbient
( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.9, 0.9, 0.9, 1.0 ) );
material->setDiffuse
( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.9, 0.9, 0.9, 1.0 ) );
#if 1
material->setSpecular
( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.7, 0.3, 0.3, 1.0 ) );
material->setShininess( osg::Material::FRONT_AND_BACK, 25 );
#endif
stateSet->setAttributeAndModes( material );
stateSet->setTextureAttributeAndModes( 0,texture, osg::StateAttribute::ON );
geode->setStateSet( stateSet );
return geode;
}
////////////////////////////////////////////////////////////////////////////////
int main( int argc, char **argv )
{
// construct the viewer.
osg::ArgumentParser arguments( &argc, argv );
osgViewer::Viewer viewer( arguments );
bool useSimpleExample = arguments.read("-s") || arguments.read("--simple") ;
osg::Node * model = NULL;
if (arguments.argc()>1 && !arguments.isOption(1) ) {
std::string filename = arguments[1];
model = osgDB::readNodeFile( filename );
if ( !model ) {
osg::notify( osg::NOTICE )
<< "Error, cannot read " << filename
<< ". Loading default earth model instead." << std::endl;
}
}
if( model == NULL )
model = CreateGlobe( );
osg::Node * node = useSimpleExample ?
CreateSimpleHierarchy( model ):
CreateAdvancedHierarchy( model );
viewer.setSceneData( node );
viewer.realize( );
viewer.run();
return 0;
}
|