0

My program changes the size of OGRE::RenderWindow at some time and later I want to get the current size of the window. But, when I use getWidth() or getHeight() on the window, they return the original size of the window.

Example code:

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

How to get correct size of the window?

Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292

1 Answers1

0

There is getActualWidth() and getActualHeight() methods in Ogre::Viewport class, so you code would look like:

Ogre::WindowEventUtilities::messagePump();

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

Here we assume that there is only 1 viewport (indexed by 0).

When you use Ogre's rendering loop, you don't have to call this messagePump() as far as I know.