Resolution change will take effect after restarting

Screen Shot 2014-04-02 at 10.20.57 pmImage unrelated.

One of my pet peeves is games which need to quit and restart when some apparently trivial setting is changed.  So when the original MMORPG Tycoon was released, I made an extra effort to make sure that you could change the game’s resolution while the game was running.  It worked, but it was problematic, and it imposed a lot of restrictions on the way the game was structured and the what I could draw in that interface.

I’ve recently added support for freely changing game resolution to Vectorstorm, in the v2 branch.  Including simple window resizing and pixel density changes (due to dragging the game window from a low-density display to a high-density display, for example).  And this has brought me the opportunity to make the “no-restart” resolution change work in MMORPG Tycoon 2 as well.

Changing resolution is a surprisingly tricky problem.  In the original VectorStorm engine, doing it involved closing the current window, creating a new window, and a new OpenGL rendering context.  This meant that every current OpenGL object needed to be re-created in the new context.  Back in the era of the original MMORPG Tycoon, that basically just meant display lists.  In the original MMORPG Tycoon, I solved the issue by not using any display lists in the main menu, where you changed resolutions.

These days, we don’t use OpenGL display lists any more, but there are a lot more objects that need to survive the resize event;  VBOs, textures, shaders, render targets, etc;  far more than I really want to recreate on the fly.  So we don’t do that any more — now we resize the data in the existing context, so that I can keep the currently loaded data still resident in the OpenGL context.  This leads to some complications, of course — I need to recreate render targets at the new window size, and similar updates.  But this isn’t the only reason that many games don’t support changing resolution at runtime.

For many games, the real problem is needing to rearrange and rebuild the onscreen user interface to fit the newly resized window in which the game is being played.  This can be surprisingly tricky, especially if text is involved.

I’ve made two fixes to address these issues:  First, MMORPG Tycoon 2 now watches for resize events, and will re-layout all of its UI if and when one happens.  This allows resizing to happen at any time (simply adjusting the size of the window in the usual way, entering/exiting full-screen mode, etc), and the game’s UI automatically updates to fit the new screen size.  Second, VectorStorm itself now remembers every bit of text that it’s rendering (via the Fragment system only), and can now be asked to re-build all renderable text fragments, to look as good as possible at the new display size.

I’m pretty excited about this.  And it’s neat to be able to take the game window from a retina screen to an external screen, and then switch to fullscreen, all seamlessly while the game is running.  Looking forward to the next milestone build, which hopefully won’t be too too far in the future.  More details very soon.

(the linked image is of a terrain rendering bug, in which large, 128×128 meter blocks of terrain appear to be ‘grid squares’, due to misalignment with their neighbors))