[osg-users] RTT With Background Alpha

J.P. Delport jpdelport at csir.co.za
Mon Apr 11 00:07:36 PDT 2011


Hi,

have a look at this thread. I posted some code there that drew a scene 
over a video.

http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/62758/

cheers
jp

On 08/04/11 21:54, Dan West wrote:
> Hi,
>
>    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)
>
>
> Code:
>
>          ...
>
>          // pass the created vertex array to the points geometry object.
>          polyGeom->setVertexArray(vertices);
>
>          polyGeom->setTexCoordArray(0,texcoords);
>          polyGeom->setTexCoordArray(1,texcoords);
>
>          osg::Vec4Array* colors = new osg::Vec4Array;
>          colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
>          polyGeom->setColorArray(colors);
>          polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
>
>          polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size()));
>
>          // 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);
>
>          polyGeom->setStateSet(stateset);
>
>          polyGeom->setUpdateCallback(new MyGeometryCallback(origin,xAxis,yAxis,zAxis,1.0,1.0/width,0.2f));
>
>          osg::Geode* geode = new osg::Geode();
>          geode->addDrawable(polyGeom);
>
>          {
>             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 );
>          }
>
>          parent->addChild(geode);
>
>      }
>
>
>
>
>    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?
>
> Thanks!
> ~ talyn
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=38340#38340
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>

-- 
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.




More information about the osg-users mailing list