2012-05-10 68 views

回答

0

我有這個問題,我需要調用XSync方法如下所示。這是OgreWidget::initialize方法的一部分,其中OgreWidget的子類QWidget。在分配m_OgreRoot並設置了渲染系統之後,initialize被稱爲OgreWidget的構造的一部分。

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