Re: [osg-users] OSG + QT and QTabWidget: Disappearing scene graph
Thanks a lot, with your tip it works ! Alistair Baxter wrote: -Original Message- From: [mailto:] On Behalf Of Lucas SART Sent: 07 September 2012 11:08 To: Subject: Re: OSG + QT and QTabWidget: Disappearing scene graph Hi, I had looking for why it doesn't work. It seems that the first tab camera projection matrix and view matrix are not valid (components = -1.#IND) and I don't know why. I tryed to look into OSG code but I don't found what is wrong... If someone have an idea it would be great ! Oddly, I think I just encountered this problem yesterday. If the QT widget ever gets resized to zero (as can happen sometimes during setup and intermediate layout stages), and osgQt::GLWidget::resizeEvent is called with width and height equal to zero, the camera projection matrix gets screwed up due to divide-by-zeroes, and never recovers because resizing always takes into account the existing camera matrix. I solved the problem by preventing osgQt::GLWidget::resizeEvent being called by my GLWidget subclass if either dimension was zero. But I suppose it would probably be better if a fix was made inside the osgQt library. ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49923#49923 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG + QT and QTabWidget: Disappearing scene graph
Hi, I had looking for why it doesn't work. It seems that the first tab camera projection matrix and view matrix are not valid (components = -1.#IND) and I don't know why. I tryed to look into OSG code but I don't found what is wrong... If someone have an idea it would be great ! Here is the code I use (running on OSG 3.0.1 and qt 4.7.3) : Code: #include QtCore/QTimer #include QtGui/QApplication #include QtGui/QGridLayout #include QTabWidget #include osgViewer/CompositeViewer #include osgViewer/ViewerEventHandlers #include osgGA/TrackballManipulator #include osgDB/ReadFile #include osgQt/GraphicsWindowQt #include iostream class ViewerWidget : public QWidget, public osgViewer::CompositeViewer { public: ViewerWidget(osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded) : QWidget() { setThreadingModel(threadingModel); // Create tab widget QTabWidget* tab = new QTabWidget(); // Add tabs tab-addTab(addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile(cow.osg) ), tab 1) ; tab-addTab(addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile(cessna.osg) ), tab 2) ; // Set layout QGridLayout* grid = new QGridLayout; grid-addWidget(tab, 0, 0) ; setLayout( grid ); setRunFrameScheme(osgViewer::ViewerBase::ON_DEMAND); _timerId = startTimer(0); } virtual ~ViewerWidget() { if (_timerId != 0) killTimer(_timerId); } QWidget* addViewWidget( osg::Camera* camera, osg::Node* scene ) { osgViewer::View* view = new osgViewer::View; view-setCamera( camera ); addView( view ); view-setSceneData( scene ); view-addEventHandler( new osgViewer::StatsHandler ); view-setCameraManipulator( new osgGA::TrackballManipulator ); osgQt::GraphicsWindowQt* gw = dynamic_castosgQt::GraphicsWindowQt*( camera-getGraphicsContext() ); return gw ? gw-getGLWidget() : NULL; } osg::Camera* createCamera( int x, int y, int w, int h, const std::string name=, bool windowDecoration=false ) { osg::DisplaySettings* ds = osg::DisplaySettings::instance().get(); osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; traits-windowName = name; traits-windowDecoration = windowDecoration; traits-x = x; traits-y = y; traits-width = w; traits-height = h; traits-doubleBuffer = true; traits-alpha = ds-getMinimumNumAlphaBits(); traits-stencil = ds-getMinimumNumStencilBits(); traits-sampleBuffers = ds-getMultiSamples(); traits-samples = ds-getNumMultiSamples(); osg::ref_ptrosg::Camera camera = new osg::Camera; camera-setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) ); camera-setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) ); camera-setViewport( new osg::Viewport(0, 0, traits-width, traits-height) ); camera-setProjectionMatrixAsPerspective( 30.0f, static_castdouble(traits-width)/static_castdouble(traits-height), 1.0f, 1.0f ); return camera.release(); } virtual bool event( QEvent* event ) { if (event-type() == QEvent::Timer) { if (static_castQTimerEvent*(event)-timerId() == _timerId) { frame(); return true; } } return QWidget::event(event); } protected: int _timerId; }; int main( int argc, char** argv ) { osg::ArgumentParser arguments(argc, argv); osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext; while (arguments.read(--SingleThreaded)) threadingModel = osgViewer::ViewerBase::SingleThreaded; while (arguments.read(--CullDrawThreadPerContext)) threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext; while (arguments.read(--DrawThreadPerContext)) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext; while (arguments.read(--CullThreadPerCameraDrawThreadPerContext)) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext; QApplication app(argc, argv); ViewerWidget* viewWidget = new ViewerWidget(threadingModel); viewWidget-setGeometry( 100, 100, 800, 600 ); viewWidget-show(); return app.exec(); } Thanks, Lucas -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49837#49837 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG + QT and QTabWidget: Disappearing scene graph
jlouis2k4 wrote: Hello Robert, Thank you for that example. It works great when I use the QTabWidget instead of the QGridLayout. However there is a problem that the first node (In the first tab) Does not show when the program is run. I can open the other tabs and see the nodes in all of them. Am I missing something here? Thank you! Cheers, Joseph I got the same problem (the first tab is empty), anyone knows how solve it ? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=49798#49798 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Cullcallback and sub camera
Hi, I am doing a render to texture system that have to take several screenshots at different location without changing the main view frame. In the scene there is a lot of Node that are affected by the camera position, so to update them I use cullcallback (osgUtil::CullVisitor::getCurrentCamera()), it works fine and on my screenshot the node are in the right location, but in the main view there are flash when the node are update for the render to texture camera... This made an ugly effect ! I don't understand why the main view display rtt camera's scene modification, I thought that the rtt camera cull traverse the graph after the rtt camera do his render after the main view do his cull traverse and his render. Am I wrong ? Is there a meaning to avoir this flashy effect ? Thank you! Cheers, Lucas -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=28039#28039 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Cullcallback and sub camera
if you want to see the effect : http://www.megaupload.com/?d=X6A0H1NK Thanks =) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=28041#28041 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] problem with transparency on rtt screenshot
Hi, I still have problems with a rtt camera use for screenshot. Without transparency it works fine, but when I try to save my screenshot in png (GL_RGBA) format I have problems with the transparency particulary when I set the diffuse of a material different to 1 I have a strange result only on the screenshot Here we have a texture (the sun) with a material : Code: osg::ref_ptrosg::Material mat = (osg::Material*)billboard-getOrCreateStateSet()-getAttribute(osg::StateAttribute::MATERIAL); if(!mat) { mat = new osg::Material; mat-setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(1,1,1,opacity)); mat-setDiffuse(osg::Material::FRONT_AND_BACK,osg::Vec4(1,1,1,opacity));//with opacity = 1 there is no problem mat-setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(1,1,1,opacity)); billboard-getOrCreateStateSet()-setAttributeAndModes(mat.get(),osg::StateAttribute::ON); } It's strange because the text is also a little transparent... Maybe a problem of render order ? take with the rtt camera : here (http://img718.imageshack.us/img718/8936/screenshot4gg.png) take with a simple print screen : here (http://img31.imageshack.us/img31/8279/3demprt.jpg) Thanks =) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=27931#27931 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with render to texture and HUD (freeze)
Somebody knows a means to make it work by leaving the render order on POST_RENDER, because it cause me some problems (particullary with the stats hud wich don't work in NESTER_RENDER) ? Thanks -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=27656#27656 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with render to texture and HUD (freeze)
up please :/ -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=27606#27606 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with render to texture and HUD
I have made some investigation, the hud that make the software freeze contains objects with a DYNAMIC data variance. I'am able to reproduce the freeze with a little code. Can somebody tell me what's wrong please ? osgBuilder.cpp : Code: #include osgBuilder.h voidcowUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor *nv) { osg::MatrixTransform*mt = dynamic_castosg::MatrixTransform *(node); osg::Matrix mrt, mpos; mpos.makeTranslate(osg::Vec3f(-6., 0., 0.)); mrt.makeRotate(angle, osg::Vec3(-0.5, 2., 1.)); mt-setMatrix(mrt * mpos); angle += 0.005; traverse(node, nv); } osgBuilder::osgBuilder(void) { } osgBuilder::~osgBuilder(void) { } osg::ref_ptrosg::GrouposgBuilder::createScene() { // Load the cow model. osg::ref_ptrosg::Node cow = osgDB::readNodeFile( ../data/cow.osg ); // Data variance is STATIC because we won't modify it. cow-setDataVariance( osg::Object::STATIC ); // Create a MatrixTransform to display the cow on the left. osg::ref_ptrosg::MatrixTransform mtLeft = new osg::MatrixTransform; mtLeft-setName( Left Cow\nDYNAMIC ); // Set data variance to DYNAMIC to let OSG know that we // will modify this node during the update traversal. mtLeft-setDataVariance( osg::Object::DYNAMIC ); // Set the update callback. mtLeft-setUpdateCallback( new cowUpdateCallback ); osg::Matrix m; m.makeTranslate( -6.f, 0.f, 0.f ); mtLeft-setMatrix( m ); mtLeft-addChild( cow ); // Create a MatrixTransform to display the cow on the right. osg::ref_ptrosg::MatrixTransform mtRight = new osg::MatrixTransform; mtRight-setName( Right Cow\nSTATIC ); // Data variance is STATIC because we won't modify it. mtRight-setDataVariance( osg::Object::STATIC ); m.makeTranslate( 6.f, 0.f, 0.f ); mtRight-setMatrix( m ); mtRight-addChild( cow ); // Create the Group root node. osg::ref_ptrosg::Group root = new osg::Group; root-setName( Root Node ); // Data variance is STATIC because we won't modify it. root-setDataVariance( osg::Object::STATIC ); root-addChild( mtLeft.get() ); root-addChild( mtRight.get() ); return root.get(); } osg::Camera* osgBuilder::createHUD() { // create a camera to set up the projection and model view matrices, and the subgraph to drawn in the HUD osg::Camera* camera = new osg::Camera; // set the projection matrix camera-setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); // set the view matrix camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera-setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer camera-setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. camera-setRenderOrder(osg::Camera::POST_RENDER); // we don't want the camera to grab event focus from the viewers main camera(s). camera-setAllowEventFocus(false); // add to this camera a subgraph to render { osg::Geode* geode = new osg::Geode(); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode-getOrCreateStateSet(); stateset-setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Vec3 position(30.0f,1000.0f,0.0f); osg::Vec3 delta(0.0f, -50.0f,0.0f); { osgText::Text* text = new osgText::Text; geode-addDrawable( text ); text-setAxisAlignment(osgText::Text::SCREEN); text-setPosition(position); text-setText( SOME TEXT ); text-setDataVariance(osg::Object::DYNAMIC); position += delta; } { osgText::Text* text = new osgText::Text; geode-addDrawable( text ); text-setAxisAlignment(osgText::Text::SCREEN); text-setPosition(position); text-setText(2nd text); text-setDataVariance(osg::Object::DYNAMIC); position += delta; } { osg::BoundingBox bb; for(unsigned int i=0;igeode-getNumDrawables();++i) { bb.expandBy(geode-getDrawable(i)-getBound()); } osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array; float depth = bb.zMin()-0.1; vertices-push_back(osg::Vec3(bb.xMin(), bb.yMax(), depth)); vertices-push_back(osg::Vec3(bb.xMin(), bb.yMin(), depth)); vertices-push_back(osg::Vec3(bb.xMax(), bb.yMin(), depth)); vertices-push_back(osg::Vec3(bb.xMax(), bb.yMax(), depth));
[osg-users] Problem with render to texture and HUD
Hi, I have got some troubles with a RTT camera and HUD camera. My scene seems like : _rootView / \ / \ RTTCam _rootParent \ / root / \ HUDsscene I try to take screenshots with a RTT camera, so I use the event KEYDOWN of a GUIEventHandler to handle the beginning of the screenshot (create rtt camera etc.) and FRAME to wait a frame and register the screenshot. It works without HUD, but when I had HUD I have 2 diffrents problem : -First : The screenshot is taken but without the HUD, Why ? -Second : The program freeze (only when the CompositeViewer isn't single threaded) ! The main thread and the other are lock in cooperativeWait ! Here is the screenshot handler code : .h Code: typedef struct s_rttCameraImage { osg::ref_ptrosg::Camera _rttCamera; osg::ref_ptrosg::Image_outputImage; } rttCameraImage; class SnapImageHandler : public osgGA::GUIEventHandler { private: int _keyImage;//key use to take a screenshot int _keyVideo;//key use to start/stop record a video rttCameraImage *_rtt;//rtt camera and image bool_takeSCEnd; //screenshot register flag VideoRecorder* _vr; PluginVideo*_plugin; SnapImage* _si; //Create the image and the rtt camera and attach it to the scene voidscreenShotInit(); //Save the image on the disk and remove the rtt camera to the scene voidscreenShotRecord(); public: SnapImageHandler(int keyImage, int keyVideo, VideoRecorder* video, PluginVideo * plugin, SnapImage *si) : _keyImage(keyImage), _keyVideo(keyVideo), _vr(video), _plugin(plugin), _si(si), _takeSCEnd(false), _rtt(0) {} ~SnapImageHandler(void){} //overload method virtual boolhandle(const osgGA::GUIEventAdapter ea,osgGA::GUIActionAdapter); }; .cpp Code: voidSnapImageHandler::screenShotInit() { _rtt = new rttCameraImage; _rtt-_outputImage = new osg::Image; if (_vr-getFilenameImage().find(.jpg) != std::string::npos || _vr-getFilenameImage().find(.jpeg) != std::string::npos) _rtt-_outputImage-allocateImage(_vr-getOutputImageSize().x(), _vr-getOutputImageSize().y(), 1, GL_RGB, GL_UNSIGNED_BYTE); else _rtt-_outputImage-allocateImage(_vr-getOutputImageSize().x(), _vr-getOutputImageSize().y(), 1, GL_RGBA, GL_UNSIGNED_BYTE); _rtt-_rttCamera = new osg::Camera; _rtt-_rttCamera-setViewMatrix(_vr-getCurrentViewMatrix()); _rtt-_rttCamera-setProjectionMatrix(_vr-getCurrentProjectionMatrix()); _rtt-_rttCamera-setReferenceFrame(osg::Transform::ABSOLUTE_RF); _rtt-_rttCamera-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _rtt-_rttCamera-setViewport(0, 0, _vr-getOutputImageSize().x(), _vr-getOutputImageSize().y()); _rtt-_rttCamera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); _rtt-_rttCamera-setRenderOrder(osg::Camera::PRE_RENDER); _rtt-_rttCamera-setRenderingCache( 0 ); _rtt-_rttCamera-setCullingActive(false); _rtt-_rttCamera-attach( osg::Camera::COLOR_BUFFER, _rtt-_outputImage.get(), 0, 0); _rtt-_rttCamera-addChild(_vr-getSceneNode()); _vr-getRootNode()-addChild(_rtt-_rttCamera); _vr-takeScreenShot(false); _takeSCEnd = true; } voidSnapImageHandler::screenShotRecord() { _vr-saveImage(_rtt-_outputImage.get(), 1); _vr-getRootNode()-removeChild(_rtt-_rttCamera.get()); _rtt-_outputImage-releaseGLObjects(); _rtt-_rttCamera-detach(osg::Camera::COLOR_BUFFER); _rtt-_rttCamera = 0; _rtt-_outputImage = 0; delete (_rtt); _rtt = 0; _si-_messagePrintPhotoOnHUD = true; _si-_messagePrintPhotoOnHUDtick = osg::Timer::instance()-tick(); _vr-_callFromSocket = false; _takeSCEnd = false; } boolSnapImageHandler::handle(const osgGA::GUIEventAdapter ea,osgGA::GUIActionAdapter aa) { osgViewer::View *viewer = dynamic_castosgViewer::View *(aa); switch(ea.getEventType()) { case (osgGA::GUIEventAdapter::FRAME): { if (_takeSCEnd)
[osg-users] Taking a screenshot using RTT
Hi, I have some problems with render to texture, I made a code and I don't understand why it didn't work. I try to take a screenshot with a render to texture. This is my code the first part : Code: int osgBuilder::start() { osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer; osg::ref_ptrmyKeyboardEventHandlerkbHdl = new myKeyboardEventHandler; osg::Matrix cameraPosition; cameraPosition.translate(0., -100., 0.); viewer-getCamera()-setViewMatrix(cameraPosition); viewer-getCamera()-setClearColor(osg::Vec4(0.3, 0.2, 0.5, 1.)); viewer-addEventHandler(kbHdl); viewer-setUpViewInWindow(200, 200, 800, 600); osg::ref_ptrosg::Grouproot = new osg::Group; osg::ref_ptrosg::GroupworldParent = new osg::Group; osg::ref_ptrosg::Groupworld = this-createScene(); //my world content root-addChild(worldParent); worldParent-addChild(world); osg::ref_ptrosg::Camera rttCamera = kbHdl-CreateRttCam(viewer, world); // Here I create the rtt camera root-addChild(rttCamera); viewer-setSceneData(root); return (viewer-run()); } Code: osg::ref_ptrosg::Camera myKeyboardEventHandler::CreateRttCam(osg::ref_ptrosgViewer::Viewer viewer, osg::ref_ptrosg::Group worldNode) { if (worldNode == 0) return 0; //get the screen size const int screenWidth = viewer-getCamera()-getGraphicsContext()-getTraits()-width; const int screenHeight = viewer-getCamera()-getGraphicsContext()-getTraits()-height; //Create the texture to render to osg::ref_ptrosg::Texture2D renderTexture = new osg::Texture2D(); renderTexture-setTextureSize(screenWidth, screenHeight); renderTexture-setInternalFormat(GL_RGBA); renderTexture-setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); renderTexture-setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); //the osg::Image that is an attribute this-textureImage = new osg::Image; textureImage-allocateImage(screenWidth, screenHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE); renderTexture-setImage(0, textureImage); //copy the viewer camera attributes into the rttCamera osg::ref_ptrosg::Camera textureCamera = new osg::Camera(*viewer-getCamera()); //to be sure textureCamera-setViewMatrix(viewer-getCamera()-getViewMatrix()); textureCamera-setReferenceFrame(osg::Transform::ABSOLUTE_RF); textureCamera-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); textureCamera-setViewport(0, 0, screenWidth, screenHeight); textureCamera-setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); textureCamera-setRenderOrder(osg::Camera::PRE_RENDER); textureCamera-attach(osg::Camera::COLOR_BUFFER, renderTexture.get()); textureCamera-attach(osg::Camera::COLOR_BUFFER, this-textureImage.get()); textureCamera-setPostDrawCallback(new MyCameraPostDrawCallBack(this-textureImage)); textureCamera-addChild(worldNode.get()); return (textureCamera); } My event handler will call a function when the touch 'p' is pressed and register the osg::image on disk but the image is empty. I also don't understand why my PostDrawCallback on the rttCamera isn't call. Any clue ? ps : Sorry for my english... ps2 : I'm a beginner in OSG Thank's a lot ! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=27227#27227 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org