Hi all,
I am trying to create a textured quad with different transparency when
looking at the front or back face. I want the quad to be opaque when looked
at from the front, but almost transparent when looked at from the back. I
thought I could do this with materials, but I get the same opacity on both
faces. This is my drawable:
osg::Geode* VOSGFloorGrid::CreateFloorQuad()
{
osg::Geode* geode = new osg::Geode;
// set up the Geometry.
osg::Geometry* geom = new osg::Geometry;
osg::Vec3 width, depth, topleft;
topleft = osg::Vec3( -Size/2.0, -Size/2.0, 0.0 );
width = osg::Vec3( Size, 0.0, 0.0 );
depth = osg::Vec3( 0.0, Size, 0.0 );
osg::Vec3Array* coords = new osg::Vec3Array(4);
(*coords)[0] = topleft;
(*coords)[1] = topleft+width;
(*coords)[2] = topleft+width+depth;
(*coords)[3] = topleft+depth;
geom->setVertexArray(coords);
osg::Vec3Array* norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3( 0.0, 0.0, 1.0 );
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec4Array* color = new osg::Vec4Array(1);
(*color)[0] = osg::Vec4(1.0f,1.0f,1.0f,0.5f);
geom->setColorArray( color );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );
osg::Vec2Array* tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,0.0f);
(*tcoords)[1].set(1.0f,0.0f);
(*tcoords)[2].set(1.0f,1.0f);
(*tcoords)[3].set(0.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4));
osg::ref_ptr< osg::Texture2D > texture = new osg::Texture2D;
texture->setImage( osgDB::readImageFile( "C:/Temp/metal.jpg" ) );
osg::StateSet* stateset = geom->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
stateset->setTextureAttributeAndModes( 0, texture.get(),
osg::StateAttribute::ON );
osg::Material* material = new osg::Material;
material->setAlpha( osg::Material::FRONT, 1.0 );
material->setAlpha( osg::Material::BACK, 0.3 );
stateset->setAttributeAndModes( material, osg::StateAttribute::ON );
geode->addDrawable( geom );
return geode;
}
What am I missing? I would be very grateful if someone can point out the
gotcha :)
Thanks!
Regards,
Morné
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/