[osg-users] qt plots over viewer

Gianni Ambrosio g.ambrosio+osg at gmail.com
Mon May 11 03:36:05 PDT 2015


Hi All,
I tried several solutions but I didn't find a full working solution yet.

Here is a piece of code that shows and is able to update the image of a qt widget but I'm not able to make the move and resize working.


Code:

void MyViewer::addOverlay(QWidget* iWidget)
{
   osgWidget::Window* osgwindow = new osgWidget::Canvas;
   osgwindow->attachMoveCallback();
   osgwindow->attachScaleCallback();
   osgwindow->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
   osgwindow->getBackground()->setColor(osg::Vec4(1, 1, 1, 0.5));

   osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new osgQt::QWidgetImage(iWidget);
   widgetImage->getQGraphicsViewAdapter()->setBackgroundColor(QColor(0xff, 0xff, 0xff, 0x80));

   osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(0,0,0), osg::Vec3(1,0,0), osg::Vec3(0,1,0), 1, 1);
   osg::Geode* geode = new osg::Geode;
   geode->addDrawable(quad);

   osg::Texture2D* texture = new osg::Texture2D(widgetImage.get());
   texture->setResizeNonPowerOfTwoHint(false);
   texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
   texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
   texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);

   osg::Camera* camera = new osg::Camera;
   camera->setProjectionResizePolicy(osg::Camera::FIXED);
   camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));
   camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   camera->setViewMatrix(osg::Matrix::identity());
   camera->setClearMask(GL_DEPTH_BUFFER_BIT);
   camera->setRenderOrder(osg::Camera::POST_RENDER);
   camera->addChild(geode);
   camera->setViewport(0, 0, 512, 384);

   osgwindow->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
   osgwindow->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
   osgwindow->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
   osgwindow->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
   osgwindow->getOrCreateStateSet()->setAttribute(new osg::Program);
   osgwindow->addChild(camera);

   osgViewer::InteractiveImageHandler* handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, camera);
   quad->setEventCallback(handler);
   quad->setCullCallback(handler);

   windowManager->addChild(osgwindow);
}




Can anybody explain me please why

osgwindow->attachMoveCallback();
osgwindow->attachScaleCallback();

do not work?

I can discard that and derive my own InteractiveImageHandler but first of all that's not what I did for other "3D widgets" where I used a drawable as child of an osgwindow's geode and move/scale works correctly.
On the other side I would like to know which is the proper way to show a qt widget in a 3D viewer so that its image can be updated but also its rectangle moved and scaled.

Regards,
Gianni

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=63698#63698








More information about the osg-users mailing list