BGE zooms in/out when changing resolution

Hello. I want to implement an options menu in my game, with a few options like VSync and Resolution. The problem is, when I use render.setWindowSize to change to a resolution higher than the default, it just zooms to the top left. When I enter a lower resolution, the game becomes smaller and black bars appear around it.
To make things weirder, when I try to take a screenshot with Fraps, the screenshot comes out fine, not zoomed in or with bars, and at the resolution I entered.
Any ideas how to solve this?

Can you supply a *.blend file?

render.setWindowSize

works fine for me.

Sure. I am using Blender 2.74, on Windows 7. What are you using?

options_test.blend (415 KB)

I think it is a problem with you starting in fullscreen. Turn off fullscreen under the options. Also instead of using keypresses, use properties to determine resolution and fullscreen.

@Thatimster If I start in windowed mode and switch to full screen in-game, I get the same effect. Not being able to have the game run in full screen mode is a serious problem and it’s not something I can abandon in favor of being able to change a resolution. Even if I run the game in windowed mode and try to increase the resolution past the resolution of the monitor (1366 x 768), it zooms.
I am using keypresses as placeholders, as this will be done using GUI in the game.

My results:

  • it starts in full-screen
  • that means took over my screen resolution (1920, 1080) which is an aspect ratio of 16:9
  • switching the window mode kept the same aspect ration but the canvas gets smaller due to the borders of the window.
  • as you set set display/framing to letterbox - I got black bars (left/right) to adjust the aspect ratio of the window which is now different (1908, 1039)
  • further reducing the size of the window resulted in black bars top/bottom (1024, 768) => 4.3. any further sizes are 4:3 too with the same horizontal adjustment bars.
  • increasing the size to (1280, 720) removed the bars as the aspect ration fits the one from startup 16:9
  • changing the size in full-screen mode did not change the resolution but rendered in a smaller area (centered). I’m not sure if you really want that effect.

Interestingly the render area of the full screen mode seems to be used for any further render. So switching to window mode did not bring back the desktop wit ha small window. It still the small render are abut with a window. Increasing the size did not increase the canvas of the window but seems to render a larger image that does not fit into the window and gets cropped. I was able to drag the window around.

I do not know if that helps you.
(I’m on windows8 btw.)

By the way, notice that the resolution applies diferently to each scene. It can’t be noticed on embbeded mode but it can in standalone. Example blend: res.blend (485 KB)

On the example the resoution changes on each camera, creating new bars of the color of world.horizon.

BGECore makes sure your window always has the same spect ratio, and therefore avoiding black bars. I guess that desktop resolution is only modified on BGE initialization, your only hope then would be to restart the BGE (the game) when modifing resolution. If restarting the game from the start is a problem you can make an entry point to direclty start the new game from the configuration menu. Of course to do any of this you need either a launcher or execute the new instance of blenderplayer from python when closing the game (in a new process).

@Monster, that did help. Thank you for taking the time.

@elmeunick9 That doesn’t really work either as I found out BGE doesn’t respect the resolution entered and it just starts at the desktop resolution. Thank you, though.

I realized I’ll have to omit resolution options from the game.

Not true. BGE starts at the resoution specified in Properties->Render->Standalone Player->Resolution, unless you check “Desktop” (cool option by the way). If you want the user to be able to change that, you need to store the custom parameters somewhere (a configuration file), and you need a way to tell blender to use those instead of the ones in the .blend file (command line paramaters), wich must be done with a launcher that reads them outside of blender. All of that is done automatically by BGECore. In BGECore is as easy as: utils.setGameProperty(“resolution”, “1080 768”). There is no relaunch function yet, but once there is all you’re asking will be done in 2 lines of code.

@elmeunick9 When I set the ‘Resolution’ to 1920 x 1080 with the ‘Desktop’ checked off, run the game in full screen and print render.getWindowWidth, render.getWindowHeight, I still get my desktop resolution back. Now, I might be misunderstanding something. The render.getWindowWidth may not return the set resolution, but rather the default monitor resolution. Is that correct?

By ‘BGECore’, I thought you meant the bge code, I did not realize it was a tool. You say you can create a launcher with it? Could it be used to set antialiasing options?

Well it only works if the resolution of the game is lower or equal to the resolution of your desktop (at least for me). For example with 1024x768, 800x600 and so on. I don’t know of any game wich resolution is greater than the desktop by the way, so probably this is standard behavior.

BGECore is a framework. It’s supossed to help making serious games in BGE, and that means Python. One of the things it does is provide you with a launcher. The launcher is a program that runs your game with a specific configuration found in a config.txt file. That configuration can be modified either directly (editing the file with a text editor) or from inside the game, with the utils provided in the framework: http://bgecore.royalwebhosting.net/utils.html

The program launches the game with any of the configurations that blenderplayer supports, that includes resolution, antialiasing, fullscreen, debug properties and some more. That configuration file can be also used to store other data about the game configuration, data that will be loaded after the game is launhced (volume, sleeptime and custom settings). Right now this system doesn’t work in directories with no write acces (don’t work on Program Files), but I’m working on it and soon it will work like any other game (creating local files when nesscesary). Finally the launcher also allows to launch the game using (optionally) a Blender copy installed in the system, this removes the need to distribuite Blender with your game but blender will need to be installed by any user who wants to play it (A message box shows up to notify the user). Alternativally you can distribuite blenderplayer in a separate folder.

As a side efect of using a launcher, you avoid any GPL issues you could have. Though the framewrok is copyrighted with a free for non-comercial use license, the launcher itself is under BSD 2-Clause, allowing it to be used and modified in any kind of project.