<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div>This is because when you set alpha to the vertices and attach also an material <br>and a blending function you have to setColorMode (AMBIENT_DIFFUSE) on the material.<br><br>Dimi<br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Vincent Bourdier <vincent.bourdier@gmail.com><br>To: OpenSceneGraph Users <osg-users@lists.openscenegraph.org><br>Sent: Tuesday, July 15, 2008 11:09:23 AM<br>Subject: Re: [osg-users] Transparency on a drawable<br><br>
<div dir="ltr"><br>Hi Paul.<br><br>Nothing changes with color's alpha changed...<br><br><br><div class="gmail_quote">2008/7/15 Paul Speed <<a rel="nofollow" ymailto="mailto:pspeed@progeeks.com" target="_blank" href="mailto:pspeed@progeeks.com">pspeed@progeeks.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>
<br>
Vincent Bourdier wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi<br>
<br>
Yes, no solutions seems to work on my problem.<br>
Because all the propositions concern nodes, I permit to remember that I am looking at a way to set alpha level on a osg::Geometry ...<br>
<br>
On node I already have a method using material : set alpha channel, and it works good...  But on my geometry nothing look to work good...<br>
<br>
This is all my geometry creator code :<br>
<br>
    osg::ref_ptr<osg::Geometry> builtGeometry(){<br>
<br>
        double alpha = 0.1;<br>
        osg::Vec4 grey(0.4,0.4,0.4,1.0);<br>
        osg::Vec4 yellow(1.0,1.0,0.0,1.0);<br>
</blockquote>
<br></div>
What happens if you put alpha for the fourth value in your color?<br>
-Paul<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">
<br>
        osg::Geometry* g = new osg::Geometry;<br>
        osg::Vec3Array* vertices    = new osg::Vec3Array();<br>
        osg::Vec3Array* normals        = new osg::Vec3Array();<br>
        osg::Vec4Array* colors        = new osg::Vec4Array();<br>
<br>
        normals->push_back(osg::Vec3(0,0,1));<br>
        colors->push_back(grey);<br>
<br>
        //----<br>
        //QUAD<br>
        vertices->push_back(osg::Vec3( _width/2.0, _height + _dist,<br>
    _offset));<br>
        vertices->push_back(osg::Vec3(-_width/2.0, _height + _dist,<br>
    _offset));<br>
        vertices->push_back(osg::Vec3(-_width/2.0, 0.0       + _dist,<br>
    _offset));<br>
        vertices->push_back(osg::Vec3( _width/2.0, 0.0       + _dist,<br>
    _offset));<br>
<br>
        if(!_empty)<br>
            g->addPrimitiveSet(new<br>
    osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));<br>
        else<br>
            g->addPrimitiveSet(new<br>
    osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,4));<br>
<br>
<br>
        //-----<br>
        //LINE<br>
<br>
        vertices->push_back(osg::Vec3(0.0, 1.0, _offset));<br>
        vertices->push_back(osg::Vec3(0.0, _dist, _offset));<br>
        colors->push_back(grey);<br>
        g->addPrimitiveSet(new<br>
    osg::DrawArrays(osg::PrimitiveSet::LINES,4,2));<br>
<br>
<br>
        //----<br>
        //LINE_LOOP<br>
<br>
        vertices->push_back(osg::Vec3( _width/2.0, _height + _dist,<br>
    _offset/2.0));<br>
        vertices->push_back(osg::Vec3(-_width/2.0, _height + _dist,<br>
    _offset/2.0));<br>
        vertices->push_back(osg::Vec3(-_width/2.0, 0.0       + _dist,<br>
    _offset/2.0));<br>
        vertices->push_back(osg::Vec3( _width/2.0, 0.0       + _dist,<br>
    _offset/2.0));<br>
<br>
        colors->push_back(yellow);<br>
        g->addPrimitiveSet(new<br>
    osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,6,4));<br>
<br>
        g->setNormalArray(normals);<br>
        g->setVertexArray(vertices);<br>
        g->setColorArray(colors);<br>
<br>
        g->setNormalBinding(osg::Geometry::BIND_OVERALL);<br>
        g->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);<br>
        g->setDataVariance(osg::Object::DYNAMIC);<br>
<br>
<br>
    //TRANSPARENCY<br>
<br>
        osg::StateSet* state = g->getOrCreateStateSet();<br>
           state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);<br>
        osg::Material* mat = new osg::Material;           mat->setAlpha(osg::Material::FRONT_AND_BACK, alpha);<br>
        state->setAttributeAndModes(mat,osg::StateAttribute::ON |<br>
    osg::StateAttribute::OVERRIDE);<br>
<br>
        osg::BlendFunc* bf = new<br>
    osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,<br>
    osg::BlendFunc::ONE_MINUS_SRC_ALPHA );<br>
        state->setAttributeAndModes(bf);<br>
<br>
        state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);<br>
        state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);<br>
<br>
        g->setStateSet(state);<br>
<br>
        return g;<br>
    }<br>
<br>
<br>
Thanks for your help.<br>
<br>
Regards,<br>
<br>
Vincent.<br>
<br></div></div>
2008/7/15 dimi christop <<a rel="nofollow" ymailto="mailto:dimi_christop@yahoo.com" target="_blank" href="mailto:dimi_christop@yahoo.com">dimi_christop@yahoo.com</a> <mailto:<a rel="nofollow" ymailto="mailto:dimi_christop@yahoo.com" target="_blank" href="mailto:dimi_christop@yahoo.com">dimi_christop@yahoo.com</a>>>:<div>
<div></div><div class="Wj3C7c"><br>
<br>
    Hi Vincent,<br>
    I see you still havent found a solution. So here I send you a<br>
    complete example of transpareny.<br>
    Its a modification of the Viewer example from the Qucik start guide.<br>
    It loads up a cow and overrides the alpha to 0.1.<br>
    Hope you can start from there.<br>
<br>
    Dimi<br>
<br>
    // Viewer Example, A minimal OSG viewer<br>
    #include <osgDB/WriteFile><br>
    #include <osg/Notify><br>
    #include <osgViewer/Viewer><br>
    #include <osgDB/ReadFile><br>
    #include <osg/MatrixTransform><br>
    #include <osg/Geode><br>
    #include <osg/Geometry><br>
    #include <osg/StateSet><br>
    #include <osg/StateAttribute><br>
    #include <osg/CullFace><br>
    #include <osg/Point><br>
    #include <osg/Light><br>
    #include <osg/LightSource><br>
    #include <osg/BlendFunc><br>
    #include <osg/Material><br>
    #include <osg/PolygonMode><br>
    #include <osg/Notify><br>
         int<br>
    main( int, char ** )<br>
    {<br>
        // Create a Viewer.<br>
        osgViewer::Viewer viewer;<br>
             // Load a model and add it to the Viewer.<br>
        osg::ref_ptr<osg::Node> nde = osgDB::readNodeFile( "cow.osg" );<br>
             // Create StateSet and Material<br>
        osg::StateSet* state2 = nde->getOrCreateStateSet();<br>
        osg::ref_ptr<osg::Material> mat2 = new osg::Material;<br>
               // Set alpha to 0.1<br>
        mat2->setAlpha(osg::Material::FRONT_AND_BACK, 0.1);<br>
        state2->setAttributeAndModes( mat2.get() ,<br>
    osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);<br>
                // Turn on blending<br>
        osg::BlendFunc* bf = new<br>
    osg::BlendFunc(osg::BlendFunc::SRC_ALPHA,<br>
    osg::BlendFunc::ONE_MINUS_SRC_ALPHA );<br>
        state2->setAttributeAndModes(bf);<br>
             viewer.setSceneData(nde.get());<br>
             if (!viewer.getSceneData())<br>
        {<br>
            osg::notify( osg::FATAL ) << "Unable to load data file.<br>
    Exiting." << std::endl;<br>
            return 1;<br>
        }<br>
<br>
        // Display, and main loop.<br>
        return viewer.run();<br>
    }<br>
<br>
    ----- Original Message ----<br>
    From: Vincent Bourdier <<a rel="nofollow" ymailto="mailto:vincent.bourdier@gmail.com" target="_blank" href="mailto:vincent.bourdier@gmail.com">vincent.bourdier@gmail.com</a><br></div></div><div class="Ih2E3d">
    <mailto:<a rel="nofollow" ymailto="mailto:vincent.bourdier@gmail.com" target="_blank" href="mailto:vincent.bourdier@gmail.com">vincent.bourdier@gmail.com</a>>><br>
    To: OpenSceneGraph Users <<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br></div><div class="Ih2E3d">
    <mailto:<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a>>><br>
    Sent: Tuesday, July 15, 2008 9:04:23 AM<br>
    Subject: Re: [osg-users] Transparency on a drawable<br>
<br>
    Hi Ulrich<br>
<br>
    thanks for help.<br>
<br>
    I use/try this code for the moment :<br>
<br>
        osg::StateSet* state = g->getOrCreateStateSet();<br>
                   state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);<br>
            osg::Material* mat =<br>
        (osg::Material*)state->getAttribute(osg::StateAttribute::MATERIAL);<br>
            if(!mat) {<br>
                mat = new osg::Material;                   }<br>
            mat->setAlpha(osg::Material::FRONT_AND_BACK, alpha);<br>
            state->setAttributeAndModes(mat,osg::StateAttribute::ON);<br>
            state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);<br>
            state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);<br>
<br>
    But nothing appear transparent...<br>
<br>
    Regards,<br>
       Vincent<br>
<br>
    2008/7/12 Ulrich Hertlein <<a rel="nofollow" ymailto="mailto:u.hertlein@sandbox.de" target="_blank" href="mailto:u.hertlein@sandbox.de">u.hertlein@sandbox.de</a><br></div>
    <mailto:<a rel="nofollow" ymailto="mailto:u.hertlein@sandbox.de" target="_blank" href="mailto:u.hertlein@sandbox.de">u.hertlein@sandbox.de</a>>>:<div class="Ih2E3d"><br>
<br>
        Vincent Bourdier wrote:<br>
<br>
            I do exactly the same things, on Nodes...<br>
<br>
                stateset->setMode(GL_BLEND,                  osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );<br>
<br>
                stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);<br>
<br>
<br>
        Are you sure you're doing this last line?  It's not in the code<br>
        snippet you posted initially...<br>
<br>
        Cheers,<br>
        /ulrich<br>
<br>
<br>
               double opacity = 0.1;<br>
<br>
                  osg::StateSet* state = mygometry->getOrCreateStateSet();<br>
                  state->setMode(GL_BLEND,osg::StateAttribute::ON|<br>
                  osg::StateAttribute::OVERRIDE);<br>
                  osg::Material* mat = (osg::Material*)state->getAttribute<br>
                  (osg::StateAttribute::MATERIAL);<br>
                  if(!mat) {<br>
                      mat = new osg::Material;<br>
                      mat->setAlpha(osg::Material::FRONT_AND_BACK, opacity);<br>
                                 state->setAttributeAndModes(mat,osg::StateAttribute::ON);<br>
                  }<br>
<br>
<br>
        _______________________________________________<br>
        osg-users mailing list<br>
        <a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br></div>
        <mailto:<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a>><div class="Ih2E3d"><br>
        <a rel="nofollow" target="_blank" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br>
<br>
<br>
<br>
    _______________________________________________<br>
    osg-users mailing list<br>
    <a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br></div>
    <mailto:<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a>><div class="Ih2E3d"><br>
    <a rel="nofollow" target="_blank" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br>
<br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a rel="nofollow" target="_blank" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</div></blockquote><div><div></div><div class="Wj3C7c">
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a rel="nofollow" ymailto="mailto:osg-users@lists.openscenegraph.org" target="_blank" href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a rel="nofollow" target="_blank" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>
</div></div></div><br>



      </body></html>