Ooops
January 22, 2021, 01:26:23 PM

Author Topic: AGK - allow users to set a custom resolution?  (Read 818 times)

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
AGK - allow users to set a custom resolution?
« on: June 12, 2020, 07:50:50 AM »
Hi,

I've recently joined a game jam and made my game with Blitz3D. The whole game was designed around the resolution of 1920x1080. Not having 'published' a game before, I unfortunately didn't take into account that some (especially laptop) PCs don't support this resolution - my mistake, but it locked out a good portion of the player base. Since Blitz3D's 2D commands don't support any resolution handling out of the box, I would either have to create assets for each resolution, write my own scaling routine, or go 2D in 3D.

I am planning to port my game to AKG, which I purchased just recently, as a project to get to know it better, but I don't want to repeat the same mistake. How do you guys tackle this subject? Which options does AGK offer for this/which one worked best for your game? Do you design it around a fixed resolution and then scale it up?

I generally feel I am having trouble to wrap my head around this whole topic, simply due to my inexperience in making games available to the public. So many design aspects are tied to the resolution (levelsize/tilesize, asset size, menu screens). I know it's important to keep the aspect ratio during the creation of the assets, but that's about it.

I would really appreciate your help/if you'd share your experience or the options in AGK you use, since I am in a weird state of not starting the project, because I don't want to change everything later down the line and lack the info of making an informed decision.

Thank you!

Offline GaborD

  • Sr. Member
  • ****
  • Posts: 349
Re: AGK - allow users to set a custom resolution?
« Reply #1 on: June 12, 2020, 08:02:02 AM »

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2919
  • elgol 2021
Re: AGK - allow users to set a custom resolution?
« Reply #2 on: June 12, 2020, 09:02:41 AM »
AGK handles that for you with Virtual Resolutions.  The window is scaled automatically, and if it's impossible to scale to an exact screen ratio it adds small bars (you can set the colour of these bars).  Bars should be small if you set to a more modern screen ratio like 1920 X 1080, and users with that resolution will see no bars.  Where as bars will be bigger if you use a more square ratio like 1024 X 768.

Code: [Select]
Global xwin = 1920
Global ywin = 1080

SetDisplayAspect( xwin / ywin )    // set aspect ratio
SetVirtualResolution( xwin, ywin ) // set VR ( if lower than window size it will scale up )
SetScissor( 0, 0, xwin, ywin )     // use the maximum available screen space, no borders
SetClearColor( 0, 0, 0 )           // dark background
SetBorderColor( 0, 0, 15 )         // some systems might need a border so set a colour

SetWindowSize( xwin, ywin, 1 )     // set resolution - 0 for a windowed game
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline blinkok

  • Sr. Member
  • ****
  • Posts: 276

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: AGK - allow users to set a custom resolution?
« Reply #4 on: June 12, 2020, 10:51:46 AM »
Thanks so much for your input! It helped me a great bunch already. I will check out the tutorial as well and then I'll try to set up a small demo first, and make sure it works correctly, before starting to port my game over.

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2919
  • elgol 2021
Re: AGK - allow users to set a custom resolution?
« Reply #5 on: June 12, 2020, 11:26:05 AM »
You're welcome, that code works perfectly on my systems.  I've tested various resolutions on the PC (the general resolution being 1920 X 1080) and on MacBook Pro the resolution is very different (2560 X 1600) but still works correctly so you shouldn't have any problems.  On the mac I get very small bars on top and bottom only, and the game is scaled correctly.
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: AGK - allow users to set a custom resolution?
« Reply #6 on: June 12, 2020, 11:44:57 AM »
That's good news. I don't want to put in the effort and notice mid way I need to redo all assets or code   :o

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2919
  • elgol 2021
Re: AGK - allow users to set a custom resolution?
« Reply #7 on: June 12, 2020, 12:03:17 PM »
Quote
That's good news. I don't want to put in the effort and notice mid way I need to redo all assets or code   :o

Yes that was my goal too so I tested AGK's commands and they work as expected.  I would just target 1920 X 1080 and let AGK take care of the rest.
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: AGK - allow users to set a custom resolution?
« Reply #8 on: June 13, 2020, 03:05:15 PM »
Quote
That's good news. I don't want to put in the effort and notice mid way I need to redo all assets or code   :o

Yes that was my goal too so I tested AGK's commands and they work as expected.  I would just target 1920 X 1080 and let AGK take care of the rest.

Yep, I've tested it this afternoon, works like a charm and as expected. Thank you for pointing me in the right direction, it was a relief to grasp this. I've done it the other way round, though. Setting a smaller resolution and scaling up, because my pixelart is small. I've read some more on this topic and a lot of indie devs seem to do it this way when they are using small art. However, I've noticed some serious screen tearing, despite setting vsync to 1. Did you have similar experiences?

I don't believe it's my code (which actually, is yours  :)))
Code: [Select]
//SET UP GRAPHICS
//game is optimized for 480x270
global resX as integer = 480
global resY as integer = 270
global gameResX as integer = 1920
global gameResY as integer = 1080
global fullscreen as integer = 1
SetUpGraphics()

function SetUpGraphics()
//calculate correct aspect ratio
SetDisplayAspect(resX / resY)
//set the optimized resolution
SetVirtualResolution(resX,resY)
//this can be set however you/the user likes it
SetWindowSize(gameResX,gameResY,fullscreen)
//60 fps
SetSyncRate(60,1)
endfunction

Might look smoother with delta time movement in place, but I believe its screen tearing.

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2919
  • elgol 2021
Re: AGK - allow users to set a custom resolution?
« Reply #9 on: June 13, 2020, 04:26:06 PM »
No I don't get any tearing, are you using Sync() more than once?  This works without tearing.

Code: [Select]
// Project: Test
// Created: 20-06-13

#Constant KEY_ESC 27
#Constant IN_PLAY 1
#Constant QUIT 2

//SET UP GRAPHICS
//game is optimized for 480x270
global resX as integer = 480
global resY as integer = 270
global gameResX as integer = 1920
global gameResY as integer = 1080
global fullscreen as integer = 1
SetUpGraphics()

function SetUpGraphics()
//calculate correct aspect ratio
SetDisplayAspect(resX / resY)
//set the optimized resolution
SetVirtualResolution(resX,resY)
//this can be set however you/the user likes it
SetWindowSize(gameResX,gameResY,fullscreen)
// background colour
SetClearColor( 147, 168, 172 )
//60 fps
SetSyncRate(60,1)
// turn on vsync
SetVSync(1)
endfunction

SetUpGraphics()

pot_image  = LoadImage( "Pot.png" )
pot_sprite = CreateSprite( pot_image )
x As Float = -16.0
y As Float = 100.0
SetSpritePosition( pot_sprite, x, y )

game_mode = IN_PLAY
Repeat
If( GetRawKeyState(KEY_ESC) ) Then game_mode = QUIT

SetSpritePosition( pot_sprite, x, y )
If( x < 480.0 - 45.0 ) Then x = x + 0.5

    Sync()
Until game_mode = QUIT
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline c0d3r9

  • Full Member
  • ***
  • Posts: 170
Re: AGK - allow users to set a custom resolution?
« Reply #10 on: June 13, 2020, 05:08:22 PM »
SetSyncRate and SetVsync shouldn´t work both together.
Laptop: Win10@64bit - i3 2x2Ghz - 8GB Ram - 1TB HDD
Desktop: Win10@64bit - AMD Ryzen 5 2400G - MSI B450 Tomahawk - 16GB Ram - 240GB SSD

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: AGK - allow users to set a custom resolution?
« Reply #11 on: June 13, 2020, 05:11:52 PM »
No I don't get any tearing, are you using Sync() more than once?  This works without tearing.

It sure does. Nice project files btw  :)) Looks like it's because I didn't use
Code: [Select]
SetVSync(1). I've read in the AGK files that Vsync is turned on by default, so I didn't use it, but apparently, I should have. Thanks!

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: AGK - allow users to set a custom resolution?
« Reply #12 on: June 13, 2020, 05:13:02 PM »
SetSyncRate and SetVsync shouldn´t work both together.
Yeah, if I use
Code: [Select]
SetVSync(1), I get 75 FPS and with
Code: [Select]
SetSyncRate(60,1) the 60 I aim for.

Offline c0d3r9

  • Full Member
  • ***
  • Posts: 170
Laptop: Win10@64bit - i3 2x2Ghz - 8GB Ram - 1TB HDD
Desktop: Win10@64bit - AMD Ryzen 5 2400G - MSI B450 Tomahawk - 16GB Ram - 240GB SSD

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2919
  • elgol 2021
Re: AGK - allow users to set a custom resolution?
« Reply #14 on: June 14, 2020, 01:43:49 PM »
Yes if you want to cap the FPS (as was requested) do as I suggested, but also think about adding delta time.

One thing I forgot to mention was if you're scaling up your pixel art everything will be blurred - so I suggest you turn off filtering.  Replace the SetUpGraphics() function:

Code: [Select]
function SetUpGraphics()
//calculate correct aspect ratio
SetDisplayAspect(resX / resY)
//set the optimized resolution
SetVirtualResolution(resX,resY)
//this can be set however you/the user likes it
SetWindowSize(gameResX,gameResY,fullscreen)
// background colour
SetClearColor( 147, 168, 172 )
// turn off smoothing filter
SetDefaultMinFilter( 0 )
SetDefaultMagFilter( 0 )
//60 fps
SetSyncRate(60,1)
// turn on vsync
SetVSync(1)
endfunction
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal