[osg-users] how to insert a QWidgetImage in a osgWidget::Window?

Gianni Ambrosio g.ambrosio+osg at gmail.com
Tue Jun 9 00:57:02 PDT 2015


Hi all,
I would like to show a Qt widget in a 3D viewer. I would like to drag it around, scale it and interact with it.

I looked at the osgQtWidgets example but didn't find exactly what I need. Since I already implemented objects that are osgWidget::Window, I thought to add the geometry got from osg::createTexturedQuadGeometry() to the osgWidget::Window geode. So I created a Texture2D object and set to the osgWidget::Window with setTextureAttributeAndModes(0, texture). I also set an InteractiveImageHandler as cull callback.

The problem is that I can't see the image.

For testing I set an image loaded from file to the texture object and it works fine. So what is missing in my code to see the Qt widget image?


Code:

   osg::ref_ptr<osgWidget::Window> window = new osgWidget::Canvas;

   float x = 0.0;
   float y = 0.0;
   float width = widget->size().width();
   float height = widget->size().height();
   osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
   osg::ref_ptr<osg::Geometry> quad;

   //std::string imageFile = "C:/Users/User/Desktop/test.jpg";
   //osg::ref_ptr<osg::Image> image = osgDB::readImageFile(imageFile);
   //texture->setImage(image.get());
   osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new osgQt::QWidgetImage(widget);
   texture->setImage(widgetImage.get());

   quad = osg::createTexturedQuadGeometry(osg::Vec3(x, y,0.0f),//center
                                          osg::Vec3(width,0.0f,0.0f),//width
                                          osg::Vec3(0.0f,height,0.0) );//height
   osg::StateSet* stateset = quad->getOrCreateStateSet();
   stateset->setTextureAttributeAndModes(0, texture.get());
   stateset->setRenderBinDetails(1, "DepthSortedBin", osg::StateSet::OVERRIDE_RENDERBIN_DETAILS); 

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

   window->getGeode()->addDrawable(quad);




Regards,
Gianni

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








More information about the osg-users mailing list