Return to Snippet

Revision: 25488
at March 31, 2010 15:51 by vorp


Initial Code
Its a modification of the Viewer example from the Qucik start guide.
It loads up a cow and overrides the alpha to 0.1. 
Hope you can start from there.

Dimi

// Viewer Example, A minimal OSG viewer 
#include <osgDB/WriteFile> 
#include <osg/Notify> 
#include <osgViewer/Viewer> 
#include <osgDB/ReadFile> 
#include <osg/MatrixTransform> 
#include <osg/Geode> 
#include <osg/Geometry> 
#include <osg/StateSet> 
#include <osg/StateAttribute> 
#include <osg/CullFace> 
#include <osg/Point> 
#include <osg/Light> 
#include <osg/LightSource> 
#include <osg/BlendFunc> 
#include <osg/Material> 
#include <osg/PolygonMode> 
#include <osg/Notify> 
 
int 
main( int, char ** ) 
{ 
    // Create a Viewer. 
    osgViewer::Viewer viewer; 
 
    // Load a model and add it to the Viewer.
    osg::ref_ptr<osg::Node> nde = osgDB::readNodeFile( "cow.osg" );
 
    // Create StateSet and Material
    osg::StateSet* state2 = nde->getOrCreateStateSet(); 
    osg::ref_ptr<osg::Material> mat2 = new osg::Material; 
    
    // Set alpha to 0.1
    mat2->setAlpha(osg::Material::FRONT_AND_BACK, 0.1); 
    state2->setAttributeAndModes( mat2.get() , osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);
    
     // Turn on blending 
    osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, 
osg::BlendFunc::ONE_MINUS_SRC_ALPHA ); 
    state2->setAttributeAndModes(bf);
 
    viewer.setSceneData(nde.get());
 
    if (!viewer.getSceneData()) 
    { 
        osg::notify( osg::FATAL ) << "Unable to load data file. Exiting." << 
std::endl; 
        return 1; 
    }

    // Display, and main loop. 
    return viewer.run(); 
}

Initial URL

                                

Initial Description
Full example

Initial Title
Transparency example 2

Initial Tags

                                

Initial Language
C++