<div dir="ltr">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><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">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><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, _offset));<br> vertices->push_back(osg::Vec3(-_width/2.0, _height + _dist, _offset));<br> vertices->push_back(osg::Vec3(-_width/2.0, 0.0 + _dist, _offset));<br>
vertices->push_back(osg::Vec3( _width/2.0, 0.0 + _dist, _offset));<br><br> if(!_empty)<br> g->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));<br> else<br> g->addPrimitiveSet(new 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 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, _offset/2.0));<br> vertices->push_back(osg::Vec3(-_width/2.0, _height + _dist, _offset/2.0));<br> vertices->push_back(osg::Vec3(-_width/2.0, 0.0 + _dist, _offset/2.0));<br>
vertices->push_back(osg::Vec3( _width/2.0, 0.0 + _dist, _offset/2.0));<br><br> colors->push_back(yellow);<br> g->addPrimitiveSet(new 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; <br>
mat->setAlpha(osg::Material::FRONT_AND_BACK, alpha);<br> state->setAttributeAndModes(mat,osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);<br><br> osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, 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>
}</blockquote><div><br>Thanks for your help.<br><br>Regards,<br><br>Vincent. <br></div><br><div class="gmail_quote">2008/7/15 dimi christop <<a href="mailto:dimi_christop@yahoo.com">dimi_christop@yahoo.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><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div>Hi Vincent,<br>
I see you still havent found a solution. So here I send you a 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> <br>int
<br>main( int, char ** )
<br>{
<br> // Create a Viewer.
<br> osgViewer::Viewer viewer;
<br> <br> // Load a model and add it to the Viewer.<br> osg::ref_ptr<osg::Node> nde = osgDB::readNodeFile( "cow.osg" );<br> <br> // Create StateSet and Material<br> osg::StateSet* state2 = nde->getOrCreateStateSet();
<br> osg::ref_ptr<osg::Material> mat2 = new osg::Material;
<br> <br> // Set alpha to 0.1<br> mat2->setAlpha(osg::Material::FRONT_AND_BACK, 0.1);
<br> state2->setAttributeAndModes( mat2.get() , osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);<br> <br> // Turn on blending
<br> osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA );
<br> state2->setAttributeAndModes(bf);<br> <br> viewer.setSceneData(nde.get());<br> <br> if (!viewer.getSceneData())
<br> {
<br> osg::notify( osg::FATAL ) << "Unable to load data file. Exiting." << std::endl;
<br> return 1;
<br> }<br><br> // Display, and main loop.
<br> return viewer.run();
<br>}<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;"><div class="Ih2E3d">----- Original Message ----<br>
From: Vincent Bourdier <<a href="mailto:vincent.bourdier@gmail.com" target="_blank">vincent.bourdier@gmail.com</a>><br>To: OpenSceneGraph Users <<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">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>
</div><div><div></div><div class="Wj3C7c"><div dir="ltr">Hi Ulrich<br><br>thanks for help.<br><br>I use/try this code for the moment :<br><br style="font-family: verdana,sans-serif;"><blockquote><span style="font-family: verdana,sans-serif;">osg::StateSet* state = g->getOrCreateStateSet();</span><br style="font-family: verdana,sans-serif;">
<span style="font-family: verdana,sans-serif;"> state->setMode(GL_BLEND,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);</span><br style="font-family: verdana,sans-serif;"><span style="font-family: verdana,sans-serif;"> osg::Material* mat = (osg::Material*)state->getAttribute(osg::StateAttribute::MATERIAL);</span><br style="font-family: verdana,sans-serif;">
<span style="font-family: verdana,sans-serif;"> if(!mat) {</span><br style="font-family: verdana,sans-serif;"><span style="font-family: verdana,sans-serif;"> mat = new osg::Material; </span><br style="font-family: verdana,sans-serif;">
<span style="font-family: verdana,sans-serif;"> }</span><br style="font-family: verdana,sans-serif;"><span style="font-family: verdana,sans-serif;"> mat->setAlpha(osg::Material::FRONT_AND_BACK, alpha);</span><br style="font-family: verdana,sans-serif;">
<span style="font-family: verdana,sans-serif;"> state->setAttributeAndModes(mat,osg::StateAttribute::ON);</span><br style="font-family: verdana,sans-serif;"><span style="font-family: verdana,sans-serif;"> state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);</span><br style="font-family: verdana,sans-serif;">
<span style="font-family: verdana,sans-serif;"> state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);</span><br></blockquote>But nothing appear transparent...<br><br>Regards,<br> Vincent<br><br><div class="gmail_quote">
2008/7/12 Ulrich Hertlein <<a rel="nofollow" href="mailto:u.hertlein@sandbox.de" target="_blank">u.hertlein@sandbox.de</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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;"><div>
I do exactly the same things, on Nodes...<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
stateset->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );<div><br>
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);<br>
</div></blockquote></blockquote>
<br>
Are you sure you're doing this last line? It's not in the code snippet you posted initially...<br>
<br>
Cheers,<br><font color="#888888">
/ulrich</font><div><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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>
</blockquote>
<br></div><div><div></div><div>
_______________________________________________<br>
osg-users mailing list<br>
<a rel="nofollow" href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a rel="nofollow" href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>
</div></div></div></div></div><br>
</div><br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br></div>