4

I try to embed ogre3d widget into qt widget on Ubuntu, but we see black screen.

When we ogre::Root::RenderWindow is used without parent widget (as a main window) everything works. But when we create ogre::Root::RenderWindow as a child window of other main window, we encounter ogre fails to work.

Here is the code:

cpp: http://pastebin.com/Rbxa5btj

header: http://pastebin.com/F4w5eQ7d

1 Answers1

0

I had this problem, and I needed to call the XSync method as shown below. This is part of a OgreWidget::initialize method, where OgreWidget subclasses QWidget. initialize is called as part of construction of OgreWidget, after m_OgreRoot is allocated and the render system is set.

setAttribute(Qt::WA_PaintOnScreen, true);
setAttribute(Qt::WA_NoSystemBackground, true);

setFocusPolicy(Qt::StrongFocus);

Ogre::String winHandle;
QX11Info info = x11Info();
winHandle = Ogre::StringConverter::toString((unsigned long)(info.display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(info.screen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));

Ogre::NameValuePairList params;
params["parentWindowHandle"] = winHandle;
params["FSAA"] = Ogre::String("8");

int w = width();
int h = height();
// Need to call XSync or the window handles will be invalid.
XSync(info.display(), False);
m_OgreWindow =
      m_OgreRoot->createRenderWindow("OgreWidget_RenderWindow",
                                     qMax(w, 640), qMax(h, 480), false, &params);

Here is the same code modified for Qt 5.1.0. QX11Info was removed for Qt 5.0.x, then added to the "extras" component for Qt 5.1.0. The new QX11Info class has only static methods.

#include <QtX11Extras/QX11Info>
...
setAttribute(Qt::WA_PaintOnScreen, true);
setAttribute(Qt::WA_NoSystemBackground, true);

setFocusPolicy(Qt::StrongFocus);

Ogre::String winHandle;
winHandle = Ogre::StringConverter::toString((unsigned long)(QX11Info::display()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned int)(QX11Info::appScreen()));
winHandle += ":";
winHandle += Ogre::StringConverter::toString((unsigned long)(winId()));

Ogre::NameValuePairList params;
params["parentWindowHandle"] = winHandle;
params["FSAA"] = Ogre::String("8");

int w = width();
int h = height();
// Need to call XSync or the window handles will be invalid.
XSync(QX11Info::display(), False);
m_OgreWindow =
      m_OgreRoot->createRenderWindow("OgreWidget_RenderWindow",
                                     qMax(w, 640), qMax(h, 480), false, &params);
Patrick
  • 2,243
  • 2
  • 23
  • 32