[osg-users] Transparency on a drawable

dimi christop dimi_christop at yahoo.com
Tue Jul 15 00:34:08 PDT 2008


Hi Vincent,
I see you still havent found a solution. So here I send you a complete example of transpareny.
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(); 
}



----- Original Message ----
From: Vincent Bourdier <vincent.bourdier at gmail.com>
To: OpenSceneGraph Users <osg-users at lists.openscenegraph.org>
Sent: Tuesday, July 15, 2008 9:04:23 AM
Subject: Re: [osg-users] Transparency on a drawable


Hi Ulrich

thanks for help.

I use/try this code for the moment :


osg::StateSet* state = g->getOrCreateStateSet();
    state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
    osg::Material* mat = (osg::Material*)state->getAttribute(osg::StateAttribute::MATERIAL);
    if(!mat) {
        mat = new osg::Material;        
    }
    mat->setAlpha(osg::Material::FRONT_AND_BACK, alpha);
    state->setAttributeAndModes(mat,osg::StateAttribute::ON);
    state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
But nothing appear transparent...

Regards,
   Vincent


2008/7/12 Ulrich Hertlein <u.hertlein at sandbox.de>:

Vincent Bourdier wrote:

I do exactly the same things, on Nodes...

stateset->setMode(GL_BLEND,   osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );

stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

Are you sure you're doing this last line?  It's not in the code snippet you posted initially...

Cheers,
/ulrich



   double opacity = 0.1;

      osg::StateSet* state = mygometry->getOrCreateStateSet();
      state->setMode(GL_BLEND,osg::StateAttribute::ON|
      osg::StateAttribute::OVERRIDE);
      osg::Material* mat = (osg::Material*)state->getAttribute
      (osg::StateAttribute::MATERIAL);
      if(!mat) {
          mat = new osg::Material;
          mat->setAlpha(osg::Material::FRONT_AND_BACK, opacity);
          state->setAttributeAndModes(mat,osg::StateAttribute::ON);
      }


_______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080715/0fcbcb8c/attachment-0003.htm>


More information about the osg-users mailing list