Hi Shekhar,

to set a transparent background you have to enable alpha when you set your 
traits 

When you set the graphic context traits 
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
you can just add the line to your configuration:
    traits->alpha = 1;
after you create a graphiccontext and associate your traits
    osg::ref_ptr<osg::GraphicsContext> graphicsContext = 
osg::GraphicsContext::createGraphicsContext(traits.get());
you can set it in your camera like this
    _viewer = new osgViewer::Viewer();
    _viewer->getCamera()->setGraphicsContext(graphicsContext);


On Jun 4, 2012, at 8:21 AM, shekhar vishwa wrote:

> Hi,
>  
> I am trying to implement the 3D overlay above current view. I am trying to 
> set the camera background color as transparent. I am using following code.
>  
> osg::Node* node= osgDB::readNodeFile( "Models/cessna.osg"); 
> osg::Camera* camera = new osg::Camera;
> camera->setViewport( 0, 0, 200, 200 );
> camera->setClearColor(osg::Vec4(1.0f,1.0,0.8f,0.2f));
> osg::StateSet* stateset = camera1->getOrCreateStateSet();
> stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
> stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
> camera->setStateSet(stateset);
> camera->setRenderOrder( osg::Camera::POST_RENDER );
> camera->setAllowEventFocus( true );
> camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
> camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
> camera->addChild( node1 );
>  
>  
> Above code only set the white background. Please help to set the camera 
> backgroud color as transparent.
>  
> Thanks
> Vishwa
> ---------- Forwarded message ----------
> From: shekhar vishwa <vishwa.shek...@gmail.com>
> Date: Sat, Jun 2, 2012 at 5:00 PM
> Subject: Set Viewport background color as transparent
> To: osg-users@lists.openscenegraph.org
> 
> 
> Hi,
>  
> I am using the OSG, but I unable to set the viewport or view backgraund color 
> as transparent.
>  
> Please help me to resolve this issue.
>  
> Thanks
> Vishwa
> 
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

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

Reply via email to