Added event handle to alter the RTT Camera's dimensions to follow the windows resizes.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14806 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -100,6 +100,58 @@ struct CommandLineOptions
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class WindowResizedHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
WindowResizedHandler()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv)
|
||||
{
|
||||
osg::Camera* camera = dynamic_cast<osg::Camera*>(object);
|
||||
if (!camera) return false;
|
||||
|
||||
const osg::FrameStamp* fs = nv->getFrameStamp();
|
||||
|
||||
if (ea.getEventType()==osgGA::GUIEventAdapter::RESIZE)
|
||||
{
|
||||
OSG_NOTICE<<"Window resized event context="<<ea.getGraphicsContext()<<" frameNumber = "<<fs->getFrameNumber()<<std::endl;
|
||||
OSG_NOTICE<<" WindowX="<<ea.getWindowX()<<std::endl;
|
||||
OSG_NOTICE<<" WindowY="<<ea.getWindowY()<<std::endl;
|
||||
OSG_NOTICE<<" WindowWidth="<<ea.getWindowWidth()<<std::endl;
|
||||
OSG_NOTICE<<" WindowHeight="<<ea.getWindowHeight()<<std::endl;
|
||||
|
||||
// reset the Camera and associated Texture's to make sure it tracks the new window size.
|
||||
int width = ea.getWindowWidth();
|
||||
int height = ea.getWindowHeight();
|
||||
camera->setViewport(0, 0, width, height);
|
||||
camera->setRenderingCache(0);
|
||||
|
||||
osg::Camera::BufferAttachmentMap& cbam = camera->getBufferAttachmentMap();
|
||||
for(osg::Camera::BufferAttachmentMap::iterator itr = cbam.begin();
|
||||
itr != cbam.end();
|
||||
++itr)
|
||||
{
|
||||
osg::Camera::Attachment& attachment = itr->second;
|
||||
if (attachment._texture.get())
|
||||
{
|
||||
osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attachment._texture.get());
|
||||
if (texture2D)
|
||||
{
|
||||
OSG_NOTICE<<"Resetting Texture size"<<std::endl;
|
||||
texture2D->setTextureSize(width, height);
|
||||
texture2D->dirtyTextureObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
osg::Node* createDistortionSubgraph(CommandLineOptions& options, osg::Node* subgraph, const osg::Vec4& clearColour)
|
||||
{
|
||||
osg::Group* distortionNode = new osg::Group;
|
||||
@@ -141,6 +193,8 @@ osg::Node* createDistortionSubgraph(CommandLineOptions& options, osg::Node* subg
|
||||
camera->addChild(subgraph);
|
||||
|
||||
distortionNode->addChild(camera);
|
||||
|
||||
camera->addEventCallback(new WindowResizedHandler());
|
||||
}
|
||||
|
||||
// set up the hud camera
|
||||
|
||||
Reference in New Issue
Block a user