我尝试将ogre3d小部件嵌入到Ubuntu的qt小部件中,但我们看到黑屏。
当我们在没有父窗口小部件(作为主窗口)的情况下使用:: Root :: RenderWindow时,一切正常。但是当我们创建ogre :: Root :: RenderWindow作为其他主窗口的子窗口时,我们遇到了ogre无法工作。
以下是代码:
答案 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, ¶ms);
以下是为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, ¶ms);