Hi Robert,
Thanks for the reply! That seems to work only if I don't need to set other
texture states. For instance, the following fails (2D texture in this case but
I need to do similar with 3D). If I comment out the sampler texture attribute,
the image is written successfully. With it commented in, image->valid() is
false .
Code:
...
camera->setFinalDrawCallback( new Capture("output.tiff") );
geode->getOrCreateStateSet()->setTextureAttributeAndModes(1, sampler,
osg::StateAttribute::ON);
geode->getOrCreateStateSet()->addUniform( new osg::Uniform("sampler", 1) );
camera->attach(osg::Camera::COLOR_BUFFER0, outputTexture);
geode->getOrCreateStateSet()->setAttributeAndModes( prog,
osg::StateAttribute::ON );
viewer.frame();
geode->getOrCreateStateSet()->removeAttribute( prog );
Capture is implemented as follows
Code:
class Capture : public osg::Camera::DrawCallback {
public:
Capture( const std::string& imagename ) : m_imageName(imagename) {}
virtual void operator () (osg::RenderInfo& renderInfo) const {
osg::ref_ptr<osg::Image> image = new osg::Image;
image->readImageFromCurrentTexture(renderInfo.getContextID(),
true);
osgDB::writeImageFile(*image, m_imageName);
}
private:
std::string m_imageName;
};
So, I'm guessing this approach doesn't work with multiple texture units? Maybe
there's a way to force a particular unit active in the callback?
Cheers,
Trystan
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43841#43841
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org