在Qt 4.8中集成OGRE 1.7.3

时间:2012-05-10 15:05:35

标签: c++ qt qt4 ogre3d

我尝试将ogre3d小部件嵌入到Ubuntu的qt小部件中,但我们看到黑屏。

当我们在没有父窗口小部件(作为主窗口)的情况下使用:: Root :: RenderWindow时,一切正常。但是当我们创建ogre :: Root :: RenderWindow作为其他主窗口的子窗口时,我们遇到了ogre无法工作。

以下是代码:

cpp:http://pastebin.com/Rbxa5btj

标题:http://pastebin.com/F4w5eQ7d

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,我需要调用XSync方法,如下所示。这是OgreWidget::initialize方法的一部分,其中OgreWidget子类QWidget。在initialize分配并设置渲染系统后,OgreWidget被称为构建m_OgreRoot的一部分。

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);

以下是为Qt 5.1.0修改的相同代码。 Qt 5.0.x删除了QX11Info,然后添加到Qt 5.1.0的“extras”组件中。新的QX11Info类只有静态方法。

#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);