Programmatically changing screen resolution

If there is something important you think is missing in the current version of ZGameEditor then you can post a feature request here!

Moderator: Moderators

Post Reply
jmp
Posts: 3
Joined: Sat May 29, 2010 7:42 am

Programmatically changing screen resolution

Post 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!
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Programmatically changing screen resolution

Post 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.
jmp
Posts: 3
Joined: Sat May 29, 2010 7:42 am

Re: Programmatically changing screen resolution

Post 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.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Programmatically changing screen resolution

Post 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
Attachments
Resolution.zgeproj
(8.1 KiB) Downloaded 743 times
jmp
Posts: 3
Joined: Sat May 29, 2010 7:42 am

Re: Programmatically changing screen resolution

Post 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!
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Re: Programmatically changing screen resolution

Post 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.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Programmatically changing screen resolution

Post 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.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: Programmatically changing screen resolution

Post 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...
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Programmatically changing screen resolution

Post 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
Post Reply