Integration of OGRE 1.7.3 in Qt 4.8

I am trying to embed an ogre3d widget into a qt widget on Ubuntu, but we see a black screen.

When we use ogre :: Root :: RenderWindow without a parent widget (as the main window), everything works. But when we create ogre :: Root :: RenderWindow as a child window of another main window, we are faced with the fact that ogre does not work.

Here is the code:

cpp: http://pastebin.com/Rbxa5btj

header: http://pastebin.com/F4w5eQ7d

+4
source share
1 answer

I had this problem and I needed to call the XSync method as shown below. This is part of the OgreWidget::initialize method, where OgreWidget subclass of QWidget . initialize is called part of building the OgreWidget , after highlighting m_OgreRoot and setting the rendering.

 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 Additional Components 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); 
0
source

Source: https://habr.com/ru/post/1411812/


All Articles