Re: [osg-users] Background image...
Thank your for your reply, Stephan. You were right. I changed my code: - (void)applicationDidFinishLaunching:(UIApplication *)application { osg::setNotifyLevel(osg::DEBUG_INFO); _viewer = new osgViewer::Viewer(); _root = new osg::Group; // //Create a Group with Box, Sphere and Cone // osg::ref_ptrosg::ShapeDrawable shape1 = new osg::ShapeDrawable; shape1-setShape(new osg::Box(osg::Vec3(-3.0f, 0.0f, 0.0f), 2.0f, 2.0f, 2.0f)); shape1-setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 0.0f)); osg::ref_ptrosg::ShapeDrawable shape2 = new osg::ShapeDrawable; shape2-setShape(new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f), 1.0f)); shape2-setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); osg::ref_ptrosg::ShapeDrawable shape3 = new osg::ShapeDrawable; shape3-setShape(new osg::Cone(osg::Vec3(0.0f, 0.0f, 0.0f), 1.0f, 1.0f)); shape3-setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); osg::ref_ptrosg::Geode geode = new osg::Geode; geode-addDrawable(shape1.get()); geode-addDrawable(shape2.get()); geode-addDrawable(shape3.get()); // try msaa. available for iOS = 4.0 osg::DisplaySettings* settings = osg::DisplaySettings::instance(); settings-setNumMultiSamples(4); OpenSceneGraph_iOSViewController* touch_handler = new OpenSceneGraph_iOSViewController(); unsigned int w(640); unsigned int h(480); osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); if (wsi) { wsi-getScreenResolution(0, w, h); } // //Camera // //create and attach ortho camera for hud text osg::ref_ptrosg::Camera hudCamera = new osg::Camera; // set the projection matrix hudCamera-setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h)); // set the view matrix hudCamera-setReferenceFrame(osg::Transform::ABSOLUTE_RF); hudCamera-setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer hudCamera-setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. hudCamera-setRenderOrder(osg::Camera::PRE_RENDER);; hudCamera-addChild(touch_handler-getDebugNode()); // // Texture for Background // osg::Geometry *rectBackground = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[1].set(0.f, 0.f, 0.f); (*vertices)[2].set((float)w, 0.f, 0.f); (*vertices)[3].set((float)w, 0.f, (float)h); rectBackground-setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, (float)h); (*texcoords)[1].set(0.0f, 0.0f); (*texcoords)[2].set((float)w, 0.0f); (*texcoords)[3].set((float)w, (float)h); rectBackground-setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,1.0f,0.0f); rectBackground-setNormalArray(normals); rectBackground-setNormalBinding(osg::Geometry::BIND_OVERALL); rectBackground-addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::Geode* Background_geode = new osg::Geode; Background_geode-addDrawable(rectBackground); // set up the texture state. osg::ref_ptrosg::TextureRectangle Background_texture = new osg::TextureRectangle; Background_texture-setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. Background_texture-setImage(osgDB::readImageFile(imagefile.jpg)); osg::StateSet* stateset = rectBackground-getOrCreateStateSet(); stateset-setTextureAttributeAndModes(0,Background_texture,osg::StateAttribute::ON); // // root // hudCamera-addChild(Background_geode); osg::Node* one = hudCamera.get(); osg::Node* two = geode.get(); one-getOrCreateStateSet()-setRenderBinDetails(1, RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2, RenderBin); _root-addChild(one); _root-addChild(two); _root-getOrCreateStateSet()-setMode(GL_DEPTH_BITS, osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_BITS, osg::StateAttribute::ON); // // viewer // _viewer-addEventHandler(touch_handler); _viewer-setSceneData(_root.get()); _viewer-setCameraManipulator(new osgGA::MultiTouchTrackballManipulator); _viewer-setThreadingModel(osgViewer::Viewer::SingleThreaded); //SingleThreaded DrawTheadPerContext _viewer-realize(); _viewer-frame(); osg::setNotifyLevel(osg::INFO); [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(updateScene) userInfo:nil
Re: [osg-users] Background image...
Hi, I am trying to learn OSG for iPhone. For this I am using the simpleExample on https://github.com/stmh/osg. Instead of the blue background color I want to load an Image. I already look at the osgHud.cpp example and I try to use some code lines. Now, I can see the child-node with geode but the background image doesn´t appear. struct SnapImage : public osg::Camera::DrawCallback { SnapImage(const std::string filename):_filename(filename),_snapImage(false) { _image = new osg::Image; } virtual void operator () (osg::RenderInfo renderInfo) const { if (!_snapImage) return; osg::notify(osg::NOTICE)Camera callbackstd::endl; osg::Camera* camera = renderInfo.getCurrentCamera(); osg::Viewport* viewport = camera ? camera-getViewport() : 0; osg::notify(osg::NOTICE)Camera callback camera viewportstd::endl; if (viewport _image.valid()) { _image-readPixels(int(viewport-x()),int(viewport-y()),int(viewport-width()),int(viewport-height()), GL_RGBA, GL_UNSIGNED_BYTE); osgDB::writeImageFile(*_image, _filename); osg::notify(osg::NOTICE)Taken screenshot, and written to '_filename'std::endl; } _snapImage = false; } std::string _filename; mutable bool_snapImage; mutable osg::ref_ptrosg::Image_image; }; struct SnapeImageHandler : public osgGA::GUIEventHandler { SnapeImageHandler(int key,SnapImage* si): _key(key), _snapImage(si) {} bool handle(const osgGA::GUIEventAdapter ea, osgGA::GUIActionAdapter) { if (ea.getHandled()) return false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYUP): { if (ea.getKey() == _key) { osg::notify(osg::NOTICE)event handlerstd::endl; _snapImage-_snapImage = true; return true; } break; } default: break; } return false; } int _key; osg::ref_ptrSnapImage _snapImage; }; // //Called once app has finished launching, create the viewer then realize. Can't call viewer-run as will //block the final inialization of the windowing system // - (void)applicationDidFinishLaunching:(UIApplication *)application { osg::setNotifyLevel(osg::DEBUG_INFO); _viewer = new osgViewer::Viewer(); _root = new osg::Group; osg::ref_ptrosg::ShapeDrawable shape1 = new osg::ShapeDrawable; shape1-setShape(new osg::Box(osg::Vec3(-3.0f, 0.0f, 0.0f), 2.0f, 2.0f, 2.0f)); shape1-setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 0.0f)); osg::ref_ptrosg::ShapeDrawable shape2 = new osg::ShapeDrawable; shape2-setShape(new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f), 1.0f)); shape2-setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); osg::ref_ptrosg::ShapeDrawable shape3 = new osg::ShapeDrawable; shape3-setShape(new osg::Cone(osg::Vec3(0.0f, 0.0f, 0.0f), 1.0f, 1.0f)); shape3-setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); osg::ref_ptrosg::Geode geode = new osg::Geode; geode-addDrawable(shape1.get()); geode-addDrawable(shape2.get()); geode-addDrawable(shape3.get()); // try msaa. available for iOS = 4.0 osg::DisplaySettings* settings = osg::DisplaySettings::instance(); settings-setNumMultiSamples(4); OpenSceneGraph_iOSViewController* touch_handler = new OpenSceneGraph_iOSViewController(); { unsigned int w(640); unsigned int h(480); osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); if (wsi) { wsi-getScreenResolution(0, w, h); } //create and attach ortho camera for hud text osg::ref_ptrosg::Camera hudCamera = new osg::Camera; // set the projection matrix hudCamera-setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h)); // set the view matrix hudCamera-setReferenceFrame(osg::Transform::ABSOLUTE_RF); hudCamera-setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer hudCamera-setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. hudCamera-setRenderOrder(osg::Camera::POST_RENDER);;
Re: [osg-users] Background image...
Hi, Am 14.07.11 12:04, schrieb Büsra Gülten: Have you any idea, what the reason could be? Any advice is really appreciated. All I can see is that you are creating a finalDrawCallback to save the current frame buffer into an jpeg file, there's AFAIK no code for loading an image and adding a geometry to the hudcamera. Am I missing something? Stephan ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] background image
Hi, I would like to put an quad as background, i would like to know if it is possible to have the required size to do this. (eg: if zFar is at 10 000 how is height and how is height?) thanks a lot ! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=27068#27068 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] background image
Anthony Face writes: I would like to put an quad as background, i would like to know if it is possible to have the required size to do this. (eg: if zFar is at 10 000 how is height and how is height?) Hi Anthony, I'd rather use a HUD-like technique as shown in the osghud example. The only difference is that you'd had to use the PRE_RENDER flag instead of the POST_RENDER one. -- Alberto ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
Hi, just change renderOder to NESTED_RENDER. it works fine. Thank you! Cheers, HUSHIWEI -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=26579#26579 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Background image...
I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
Hi Alessandro, nah. That wont do the job. I did a quick test, and here is how I made it work go the the osgHUD example and: 1. createHUD, set for the camera: camera-setRenderOrder(osg::Camera::NESTED_RENDER); 2. in main, about line 362, where you load your scene without arguments osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2,RenderBin); group-addChild(one); group-addChild(two); group-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // add the HUD subgraph. //if (scene.valid()) group-addChild(scene.get()); //group-addChild(createHUD()); // set the scene to render viewer.setSceneData(group.get()); this is working code. Might be another way, but this will help you I think Let me know if it works for you Nick http://www.linkedin.com/in/tnick Sent from Ünalan, İstanbul, Turkey On Sat, Dec 19, 2009 at 11:16 AM, alessandro terenzi a.tere...@gmail.comwrote: I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
Thank you very much Nick, it worked fine, I just changed this: group -getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); into this: one-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); Regards. Alessandro On Sat, Dec 19, 2009 at 12:42 PM, Trajce Nikolov nikolov.tra...@gmail.comwrote: Hi Alessandro, nah. That wont do the job. I did a quick test, and here is how I made it work go the the osgHUD example and: 1. createHUD, set for the camera: camera-setRenderOrder(osg::Camera::NESTED_RENDER); 2. in main, about line 362, where you load your scene without arguments osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2,RenderBin); group-addChild(one); group-addChild(two); group-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // add the HUD subgraph. //if (scene.valid()) group-addChild(scene.get()); //group-addChild(createHUD()); // set the scene to render viewer.setSceneData(group.get()); this is working code. Might be another way, but this will help you I think Let me know if it works for you Nick http://www.linkedin.com/in/tnick Sent from Ünalan, İstanbul, Turkey On Sat, Dec 19, 2009 at 11:16 AM, alessandro terenzi a.tere...@gmail.comwrote: I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
u r welcome .. Glad it works Nick http://www.linkedin.com/in/tnick Sent from Devlet, Ankara, Turkey On Sat, Dec 19, 2009 at 2:49 PM, alessandro terenzi a.tere...@gmail.comwrote: Thank you very much Nick, it worked fine, I just changed this: group -getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); into this: one -getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); Regards. Alessandro On Sat, Dec 19, 2009 at 12:42 PM, Trajce Nikolov nikolov.tra...@gmail.com wrote: Hi Alessandro, nah. That wont do the job. I did a quick test, and here is how I made it work go the the osgHUD example and: 1. createHUD, set for the camera: camera-setRenderOrder(osg::Camera::NESTED_RENDER); 2. in main, about line 362, where you load your scene without arguments osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2,RenderBin); group-addChild(one); group-addChild(two); group-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // add the HUD subgraph. //if (scene.valid()) group-addChild(scene.get()); //group-addChild(createHUD()); // set the scene to render viewer.setSceneData(group.get()); this is working code. Might be another way, but this will help you I think Let me know if it works for you Nick http://www.linkedin.com/in/tnick Sent from Ünalan, İstanbul, Turkey On Sat, Dec 19, 2009 at 11:16 AM, alessandro terenzi a.tere...@gmail.com wrote: I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
There is DepthSortedBin as well osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,DepthSortedBin); two-getOrCreateStateSet()-setRenderBinDetails(2,DepthSortedBin); group-addChild(one); group-addChild(two); one-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); Nick http://www.linkedin.com/in/tnick Sent from Devlet, Ankara, Turkey On Sat, Dec 19, 2009 at 2:49 PM, alessandro terenzi a.tere...@gmail.comwrote: Thank you very much Nick, it worked fine, I just changed this: group -getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); into this: one -getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); Regards. Alessandro On Sat, Dec 19, 2009 at 12:42 PM, Trajce Nikolov nikolov.tra...@gmail.com wrote: Hi Alessandro, nah. That wont do the job. I did a quick test, and here is how I made it work go the the osgHUD example and: 1. createHUD, set for the camera: camera-setRenderOrder(osg::Camera::NESTED_RENDER); 2. in main, about line 362, where you load your scene without arguments osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2,RenderBin); group-addChild(one); group-addChild(two); group-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // add the HUD subgraph. //if (scene.valid()) group-addChild(scene.get()); //group-addChild(createHUD()); // set the scene to render viewer.setSceneData(group.get()); this is working code. Might be another way, but this will help you I think Let me know if it works for you Nick http://www.linkedin.com/in/tnick Sent from Ünalan, İstanbul, Turkey On Sat, Dec 19, 2009 at 11:16 AM, alessandro terenzi a.tere...@gmail.com wrote: I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image...
You can use an additional Camera for this, but that's really overkill for a fullscreen quad. I would just draw a quad. Use a low render bin so that it renders first. Use a vertex shader to do the transform (make it fullscreen and put it on the far plane) and a fragment shader for the texturing. Set the depth test to ALWAYS and disable the parent camera clear. Paul Martz Skew Matrix Software LLC _http://www.skew-matrix.com_ http://www.skew-matrix.com/ +1 303 859 9466 Trajce Nikolov wrote: Hi Alessandro, nah. That wont do the job. I did a quick test, and here is how I made it work go the the osgHUD example and: 1. createHUD, set for the camera: camera-setRenderOrder(osg::Camera::NESTED_RENDER); 2. in main, about line 362, where you load your scene without arguments osg::ref_ptrosg::Group group = new osg::Group; osg::Node* one = createHUD(); // this will be your background image osg::Node* two = scene.get(); one-getOrCreateStateSet()-setRenderBinDetails(1,RenderBin); two-getOrCreateStateSet()-setRenderBinDetails(2,RenderBin); group-addChild(one); group-addChild(two); group-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); two-getOrCreateStateSet()-setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // add the HUD subgraph. //if (scene.valid()) group-addChild(scene.get()); //group-addChild(createHUD()); // set the scene to render viewer.setSceneData(group.get()); this is working code. Might be another way, but this will help you I think Let me know if it works for you Nick http://www.linkedin.com/in/tnick Sent from Ünalan, İstanbul, Turkey On Sat, Dec 19, 2009 at 11:16 AM, alessandro terenzi a.tere...@gmail.comwrote: I'd like to create a fixed background for an osg application, much like a HUD but while the HUD is always on top of the scene, I need to have an image always behind any 3D object. I tried to modify the example about HUDs by changing: setRenderOrder(osg::Camera::POST_RENDER); into this: setRenderOrder(osg::Camera::PRE_RENDER); but I guess that this is not sufficent to achive my goal, because actually the background image is not displayed at all (or maybe it is covered by the scene...). How can I create the desired effect? Thanks in advance. Alessandro ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Background image
Hi ! I m trying to put an image in background behind my 3D scene . the problem is that the 2d image is in middle of 3D scene . any sugestion to resolve this ? thks :) ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image
no, I m using hud but my 3d objects are behind the hud. I want my 3d objets in front of hud . ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image
Hi Carlos, you need to put the HUD in a render bin that is drawn before everything else. Setting the render bin to 0 or 1 should work (because I think other geometry would default to bin 2) The HUD also needs to be configured to not write to the z buffer. Christian ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image
turn off depth testing something like this: camera_-setViewport( 0, 0, image_-s(), image_-t() ); camera_-setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT ); // *** this is also pretty key ** camera_-setRenderOrder( osg::Camera::PRE_RENDER, 1 ); camera_-attach( osg::Camera::COLOR_BUFFER, texture_.get() ); camera_-setClearMask( GL_COLOR_BUFFER_BIT ); // do not want to clear bg image camera_-setReferenceFrame( osg::Transform::ABSOLUTE_RF ); camera_-setViewMatrix( osg::Matrix::identity() ); // *** make sure depth is off *** camera_-getOrCreateStateSet()-setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF ); From: Carlos Sanches ces...@gmail.com To: OpenSceneGraph Users osg-users@lists.openscenegraph.org Sent: Friday, July 3, 2009 2:22:27 PM Subject: Re: [osg-users] Background image no, I m using hud but my 3d objects are behind the hud. I want my 3d objets in front of hud . ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image texture rescaling problem
Robert Osfield wrote: Hi John, On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote: Thanks Robert, I have this working now without rescaling the image. My solution was to pad the image with zeros making it a power of two and then specify the correct percentage of the image to use as 2D texture. Not sure if this is the best solution but it works and is fast enough for me. This is not an elegant way to tackle the problem, workable yes, but I'd recommend spending a little time - readying up about TextureRectangle or just disabling the resize of non power of two textures, you'll end up with a more efficient and elegant solution. I've used two of these methods to avoid the resizing penalty. The first was to use John's solution to create power-of-two images and only fill it with a subimage that is actually used. I then use the texture matrix to change the texture coordinates so no recoding is necessary. This has worked very well for my application. The second method was to use the TextureRectangle solution, but there are a few drawbacks to this method: it may not be hardware-accelerated, especially on older cards; you lose the ability to generate mipmapped textures; and your texture coordinates become non-normalized, so that you have to know the size of the image when you set up your scene if you do anything fancy. Texture Rectangles are useful but are not the ultimate solution to all problems. Eric ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image texture rescaling problem
Thanks Robert, I have this working now without rescaling the image. My solution was to pad the image with zeros making it a power of two and then specify the correct percentage of the image to use as 2D texture. Not sure if this is the best solution but it works and is fast enough for me. -- John On 9/13/07, Robert Osfield [EMAIL PROTECTED] wrote: Hi John, The rescaling is done on non power of two textures by default, rescaling is slow op so best avoided. You have two choices to disable the resize of the non power of two texture as you have down to move to using TextureRectangle instead of Texture2D. If moving to the TextureRectangle you'll need to move you pixel coords rather than normal non dimensions texture coords - see osgtexturerectangle example. Robert. On 9/12/07, John Steinbis [EMAIL PROTECTED] wrote: For an AR project, I need to render a model with video image as background. My program is based around osgViewer using osg v2.0. I found an example for a HUD and with a few changes made it work as background. The code can be found below. The code runs ok but there is a problem occurring that I cannot figure out. Any ideas … ? When new images are loaded, they are rescaled for some reason. This adds a noticeable delay, ~250 ms, and distorts the images, which is not acceptable. Output looks like Scaling image 'x' from (720,480) to (512,512). To prevent resizing I use BGTexture-setResizeNonPowerOfTwoHint(false). To update an image I use BGTexture-setImage(newImg). Thanks, John root-addChild(BGProjectionMatrix); BGProjectionMatrix-setMatrix(osg::Matrix::ortho2D(0,width,0,height)); BGProjectionMatrix-addChild(BGModelViewMatrix); BGModelViewMatrix-setMatrix(osg::Matrix::identity()); BGModelViewMatrix-setReferenceFrame(osg::Transform::ABSOLUTE_RF); BGModelViewMatrix-addChild( BGGeode ); BGTexture-setDataVariance(osg::Object::DYNAMIC); BGTexture-setResizeNonPowerOfTwoHint(false); // -- BGTexture-setImage(BGImage); BGGeode-addDrawable(BGBackgroundGeometry); BGGeode-setStateSet(BGStateSet); BGBackgroundVertices-push_back( osg::Vec3( 0, 0, 0) ); BGBackgroundVertices-push_back( osg::Vec3(width, 0, 0) ); BGBackgroundVertices-push_back( osg::Vec3(width, height, 0) ); BGBackgroundVertices-push_back( osg::Vec3( 0, height, 0) ); (*texcoords)[0].set(0.0f,0.0f); (*texcoords)[1].set(1.0f,0.0f); (*texcoords)[2].set(1.0f,1.0f); (*texcoords)[3].set(0.0f,1.0f); BGcolors-push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); BGnormals-push_back(osg::Vec3(1.0f,1.0f,1.0f)); BGBackgroundGeometry-setTexCoordArray(0,texcoords); BGBackgroundGeometry-setColorArray(BGcolors); BGBackgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL); BGBackgroundGeometry-setNormalArray(BGnormals); BGBackgroundGeometry-setNormalBinding(osg::Geometry::BIND_OVERALL); BGBackgroundGeometry-addPrimitiveSet(BGBackgroundIndices); BGBackgroundGeometry-setVertexArray(BGBackgroundVertices); BGBackgroundIndices-push_back(0); BGBackgroundIndices-push_back(1); BGBackgroundIndices-push_back(2); BGBackgroundIndices-push_back(3); BGStateSet-setTextureAttributeAndModes(0,BGTexture,osg::StateAttribute::ON); BGStateSet-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); BGStateSet-setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); BGStateSet-setRenderBinDetails( 1, RenderBin); ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image texture rescaling problem
Hi John, On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote: Thanks Robert, I have this working now without rescaling the image. My solution was to pad the image with zeros making it a power of two and then specify the correct percentage of the image to use as 2D texture. Not sure if this is the best solution but it works and is fast enough for me. This is not an elegant way to tackle the problem, workable yes, but I'd recommend spending a little time - readying up about TextureRectangle or just disabling the resize of non power of two textures, you'll end up with a more efficient and elegant solution. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image texture rescaling problem
I tryed disabling the resize of non power of two textures by using setResizeNonPowerOfTwoHint but it did not seem to have any effect. Do you think there is a bug or I just wasnt doing something right? You can find the line where I tried this in my original post. I havent been able to figure out how to set the position of a window. How can I do this? Also, if I try to drag the window to a new location, it freezes. -- js On 9/15/07, Robert Osfield [EMAIL PROTECTED] wrote: Hi John, On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote: Thanks Robert, I have this working now without rescaling the image. My solution was to pad the image with zeros making it a power of two and then specify the correct percentage of the image to use as 2D texture. Not sure if this is the best solution but it works and is fast enough for me. This is not an elegant way to tackle the problem, workable yes, but I'd recommend spending a little time - readying up about TextureRectangle or just disabling the resize of non power of two textures, you'll end up with a more efficient and elegant solution. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Background image texture rescaling problem
On 9/15/07, John Steinbis [EMAIL PROTECTED] wrote: I tryed disabling the resize of non power of two textures by using setResizeNonPowerOfTwoHint but it did not seem to have any effect. Do you think there is a bug or I just wasnt doing something right? You can find the line where I tried this in my original post. It'll only work if you have capable hardware - i.e. Gefore6 series or later, otherwise it'll detect this an resize things as usual. I havent been able to figure out how to set the position of a window. How can I do this? Also, if I try to drag the window to a new location, it freezes. We'll if you want to ask this, then start a new thread. Also in the meantime look at the osgwindow example. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Background image texture rescaling problem
For an AR project, I need to render a model with video image as background. My program is based around osgViewer using osg v2.0. I found an example for a HUD and with a few changes made it work as background. The code can be found below. The code runs ok but there is a problem occurring that I cannot figure out. Any ideas … ? When new images are loaded, they are rescaled for some reason. This adds a noticeable delay, ~250 ms, and distorts the images, which is not acceptable. Output looks like Scaling image 'x' from (720,480) to (512,512). To prevent resizing I use BGTexture-setResizeNonPowerOfTwoHint(false). To update an image I use BGTexture-setImage(newImg). Thanks, John root-addChild(BGProjectionMatrix); BGProjectionMatrix-setMatrix(osg::Matrix::ortho2D(0,width,0,height)); BGProjectionMatrix-addChild(BGModelViewMatrix); BGModelViewMatrix-setMatrix(osg::Matrix::identity()); BGModelViewMatrix-setReferenceFrame(osg::Transform::ABSOLUTE_RF); BGModelViewMatrix-addChild( BGGeode ); BGTexture-setDataVariance(osg::Object::DYNAMIC); BGTexture-setResizeNonPowerOfTwoHint(false); // -- BGTexture-setImage(BGImage); BGGeode-addDrawable(BGBackgroundGeometry); BGGeode-setStateSet(BGStateSet); BGBackgroundVertices-push_back( osg::Vec3( 0, 0, 0) ); BGBackgroundVertices-push_back( osg::Vec3(width, 0, 0) ); BGBackgroundVertices-push_back( osg::Vec3(width, height, 0) ); BGBackgroundVertices-push_back( osg::Vec3( 0, height, 0) ); (*texcoords)[0].set(0.0f,0.0f); (*texcoords)[1].set(1.0f,0.0f); (*texcoords)[2].set(1.0f,1.0f); (*texcoords)[3].set(0.0f,1.0f); BGcolors-push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); BGnormals-push_back(osg::Vec3(1.0f,1.0f,1.0f)); BGBackgroundGeometry-setTexCoordArray(0,texcoords); BGBackgroundGeometry-setColorArray(BGcolors); BGBackgroundGeometry-setColorBinding(osg::Geometry::BIND_OVERALL); BGBackgroundGeometry-setNormalArray(BGnormals); BGBackgroundGeometry-setNormalBinding(osg::Geometry::BIND_OVERALL); BGBackgroundGeometry-addPrimitiveSet(BGBackgroundIndices); BGBackgroundGeometry-setVertexArray(BGBackgroundVertices); BGBackgroundIndices-push_back(0); BGBackgroundIndices-push_back(1); BGBackgroundIndices-push_back(2); BGBackgroundIndices-push_back(3); BGStateSet-setTextureAttributeAndModes(0,BGTexture,osg::StateAttribute::ON); BGStateSet-setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); BGStateSet-setRenderingHint( osg::StateSet::TRANSPARENT_BIN ); BGStateSet-setRenderBinDetails( 1, RenderBin); ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org