Page 1 of 1

Programmatically changing screen resolution

Posted: Thu Sep 24, 2015 5:54 pm
by jmp
Hi there!

Any chance we could get the ability to programmatically set the screen resolution?

I'd like to be able to somehow query screen modes/resolutions that are supported by the system, and set one of those programmatically.

A use case for such a feature would be an in-game options menu, for example. At the moment resolution options are very limited and it would be nice to have more control over such things.

Thank you for considering!

Re: Programmatically changing screen resolution

Posted: Fri Sep 25, 2015 8:06 am
by VilleK
Hi,

What is easy to do and we should do first is adding more built-in resolution options because those listed are old. Can you recommend a list of resolution options? Then we'll see if I can add code to be able to change between them at runtime.

Re: Programmatically changing screen resolution

Posted: Fri Sep 25, 2015 3:12 pm
by jmp
I wouldn't really recommend any hard-coded list because nowadays there are too many different screen sizes and aspect ratios. If my resolution happens to not be on that list, then I'm stuck with using windowed mode, or having black borders around the screen, or even with a scaled screen with a wrong aspect ratio or something.

For example the laptop I'm using right now uses 1600x900 resolution which is already a bit rare (although 16:9 aspect ratio). But my desktop uses 1280x1024 (5:4), and I have another laptop that has this weird 1366x768 (683:384!!!) resolution.

So most convenient would be if I could just query the available screen modes from the system, and pick one of those. A bit like how libraries like SDL let you do.

Re: Programmatically changing screen resolution

Posted: Fri Sep 25, 2015 3:50 pm
by Kjell
Hi jmp,

I don't see why anyone would want to use a resolution that isn't the native resolution of their monitor, but below is a example on how to get all supported resolutions ( on Windows ).

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary ModuleName="user32" Source="byte EnumDisplaySettingsA(string lpszDeviceName, int iModeNum, xptr lpDevMode){}"/>
    <ZExpression>
      <Expression>
<![CDATA[int index;
int[39] dm;
string resolution = "";

while(EnumDisplaySettingsA(null, index++, dm))
{
  string r = intToStr(dm[27])+"x"+intToStr(dm[28]);

  if(r != resolution)
  {
    resolution = r;
    trace(resolution);
  }
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
</ZApplication>
+ Attached is a simple demo, use left / right arrow to select a resolution and press spacebar to switch to it.

K

Re: Programmatically changing screen resolution

Posted: Fri Sep 25, 2015 6:56 pm
by jmp
Woah, that's pretty sweet!! I actually completely missed the fact that I can call external libraries from within ZGE. :shock:

Of course a cross-platform solution would be optimal, but this is already great. Thanks Kjell!

Re: Programmatically changing screen resolution

Posted: Sat Sep 26, 2015 10:21 pm
by Imerion
Can you recommend a list of resolution options? Then we'll see if I can add code to be able to change between them at runtime.
This far I have been using 1024x576, 1360x768, 1366x768, so those are the ones I'd like most on the list. 1920x1080 would be useful to have too.

Re: Programmatically changing screen resolution

Posted: Mon Sep 28, 2015 8:29 am
by VilleK
Real nice example Kjell!
Kjell wrote:I don't see why anyone would want to use a resolution that isn't the native resolution of their monitor
I can agree with this. When is it really relevant to change resolutions, in practice? In the older days you would try setting lower resolution if the game didn't run at full frame rate but these days I'd expect any game to run in full frame rate on the default native monitor resolution.

Re: Programmatically changing screen resolution

Posted: Mon Sep 28, 2015 1:05 pm
by Rado1
Kjell wrote:I don't see why anyone would want to use a resolution that isn't the native resolution of their monitor
I use windowed mode of ZGE application with small resolution (e.g., 400x320) for OpenGL debugging purposes. For instance, gDebugger does not run well for full-screen applications and I want to see both windows, ZGE and gDebugger, on my screen side-by-side. But this is quite an exception for usual ZGE users, I agree...

Re: Programmatically changing screen resolution

Posted: Mon Sep 28, 2015 1:19 pm
by Kjell
Hi Rado1,
Rado1 wrote:I use windowed mode of ZGE application with small resolution (e.g., 400x320) for OpenGL debugging purposes.
Windowed mode is something else entirely. I do appreciate it when PC games that allow windowed mode offer a slew of resolutions .. but in that case the desktop / video-out resolution doesn't have to change, nor do they have to be supported by the GPU & monitor ( obviously ).

K