[osg-users] RTT With Background Alpha
osgforum at tevs.eu
Fri Apr 8 12:54:16 PDT 2011
I'm trying to create an overlay texture rendered using render to texture (RTT).
I've been playing around with the osgprerender example, but can't get the effect I'm trying for.
I am trying to use the RTT texture as an overlay over an existing texture, so (starting at the stock osgprerender example) I duplicated the setTextCoordArray line to apply the texture coordinates to both texture units 0 and 1. I changed the RTT texture application to use texture unit 1, and created a texture and applied that to texture unit 0. (see below)
// pass the created vertex array to the points geometry object.
osg::Vec4Array* colors = new osg::Vec4Array;
// new we need to add the texture to the Drawable, we do so by creating a
// StateSet to contain the Texture StateAttribute.
osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(1, texture, osg::StateAttribute::ON);
osg::Geode* geode = new osg::Geode();
osg::Texture2D* flagTex = new osg::Texture2D();
flagTex->setInternalFormat( GL_RGBA );
flagTex->setWrap( osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_BORDER );
flagTex->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER );
flagTex->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER );
flagTex->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
flagTex->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
flagTex->setDataVariance( osg::Object::DYNAMIC ); // protect from being optimized away as static state.
flagTex->setImage( osgDB::readImageFile("Images/american-flag.png") );
polyGeom->getOrCreateStateSet()->setTextureAttributeAndModes( 0, flagTex );
This is sort of what I'm going for (only the RRT overlay won't be a spinning 3d model), however everything behind the model is colored with the RTT camera's background color. (see screenshot below)
(screenshot omitted due to lack of posts)
At this point, I'd like to simply set the background color to have some alpha ( 0.0f ), and be done with this issue, but I have been unable to disable the background and make it completely transparent.
Any OSG guru's out there know how to do what I'm trying to do?
Read this topic online here:
More information about the osg-users