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

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

Programmatically changing screen resolution

Postby jmp » Thu Sep 24, 2015 5:54 pm

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: 1912
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Programmatically changing screen resolution

Postby VilleK » Fri Sep 25, 2015 8:06 am

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

Postby jmp » Fri Sep 25, 2015 3:12 pm

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: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Re: Programmatically changing screen resolution

Postby Kjell » Fri Sep 25, 2015 3:50 pm

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.32 KiB) Downloaded 78 times

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

Re: Programmatically changing screen resolution

Postby jmp » Fri Sep 25, 2015 6:56 pm

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: 196
Joined: Sun Feb 09, 2014 4:42 pm

Re: Programmatically changing screen resolution

Postby Imerion » Sat Sep 26, 2015 10:21 pm

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: 1912
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Programmatically changing screen resolution

Postby VilleK » Mon Sep 28, 2015 8:29 am

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: 770
Joined: Wed May 05, 2010 12:16 pm

Re: Programmatically changing screen resolution

Postby Rado1 » Mon Sep 28, 2015 1:05 pm

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: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Re: Programmatically changing screen resolution

Postby Kjell » Mon Sep 28, 2015 1:19 pm

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


Return to “Feature requests”

Who is online

Users browsing this forum: No registered users and 1 guest