如何在调整大小后获得正确大小的OGRE :: RenderWindow?

时间:2014-10-14 06:34:54

标签: ogre

我的程序会在某个时间更改OGRE::RenderWindow的大小,之后我想获得当前窗口的大小。但是,当我在窗口上使用getWidth()getHeight()时,它们会返回窗口的原始大小。

示例代码:

OGRE::RenderWindow* win;

// ... OGRE is initialized
// Window is drawn 1024x768 using size from ogre.cfg

// ... lots of code ...

// Window size is changed and it works
win->resize(800, 600);

// ... lots of code ...

// Window is still visibly 800x600, but this call
// returns 1024x768 (the original size)
int w = win->getWidth();  // Returns 1024
int h = win->getHeight(); // Returns 768

如何获得正确的窗口大小?

1 个答案:

答案 0 :(得分:0)

Ogre::Viewport类中有getActualWidth()和getActualHeight()方法,因此您的代码如下所示:

Ogre::WindowEventUtilities::messagePump();

int w = win->getViewport(0)->getActualWidth();
int h = win->getViewport(0)->getActualHeight();

这里我们假设只有1个视口(索引为0)。

当你使用Ogre的渲染循环时,你不必在我知道的情况下调用这个messagePump()。