From 890aea95371156adaf1ab72dfd09400973d5fede Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Mar 2015 17:58:34 +0000 Subject: [PATCH] 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 --- examples/osgdistortion/osgdistortion.cpp | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index 6cba18fb7..b3181c632 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -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(object); + if (!camera) return false; + + const osg::FrameStamp* fs = nv->getFrameStamp(); + + if (ea.getEventType()==osgGA::GUIEventAdapter::RESIZE) + { + OSG_NOTICE<<"Window resized event context="<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