Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / setwindowsize v setvirtualresolution

Author
Message
KayDee
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location:
Posted: 7th Apr 2020 10:21
I'm new to the AppGameKit language, having been spoilt in the past by BLITZ. I thought I would purchase a new language that is more up-to-date.

But I keep hitting snags...or something that just doesn't make any sense.

For instance...

test 1 -------------------------------------------------------------------------------------------------
setwindowsize(1024,768,1)

does not set the window size to 1024,768?? and my sprites are MASSIVE, (I get the desktop size)
there is a black stripe on both the left and right and the mouse is allowed to go outside the screen size.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

test 2 -------------------------------------------------------------------------------------------------
setwindowsize(1024,768,1)
SetVirtualResolution(1024,768)

sprites are 'normal' sized and there is a black stripe on both the left and right
and the mouse is allowed to go outside the screen size.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


test 3 -------------------------------------------------------------------------------------------------
setwindowsize(1024,768,1)
SetVirtualResolution(1024,768)
SetScissor( 0,0,1,1 )

I get a black screen
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

What I am after is a screen size set to a size I set without the black stripes and
not allow the mouse outside of this area.

Can anybody give me a clue as to what I doing wrong?
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 7th Apr 2020 12:25
SetWindowSize, sets the size of the Display Output Window...
So let's say you have a 1080p Display, you want SetWindowSize( 1920, 1080, 1 )

SetVirtualResolution, sets the Rendering Output Resolution...
So, let's say you want to actually Render at 4K, you would SetVirtualResolution( 3840, 2160 )

GetVirtualWidth and GetVirtualHeight will return whatever the Virtual Resolution is.
Where-as GetDeviceWidth and GetDeviceHeight return the Window Size

SetScissor( 0, 0, 0, 0 ) will use the full display area... the ONLY usage I've considered this being potentially useful for, is creating a "Cinematic" Border which crops the output with Black Borders.
Still even then, it's just as easy to make a Black Image and turn it into Resized Sprites that do the same job.
Note it DOES NOT change the actual Screen Space Coordinates... if it did, then it'd be useful as an Overscan Compensation Tool; while still outputting the same intended Resolution and Window Size.
So yeah... I'd personally recommend just leaving it as above.



You can see what I mean with that sample code
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 7th Apr 2020 15:33
SetWindowSize():
AGK will attempt to set the window to the size specified. If it can't, it will create a window as close as it can. When you go fullscreen by adding a 1 at the end, it will create a borderless window the same dimentions as your desktop. Unlike other graphic engines, AppGameKit does not change your desktop resolution. So if you try to enter a 1024,768 resolution, but your desktop is currently set to 800, 600, then you will get an 800, 600 screen. Also, AppGameKit will try and maintain a square pixel aspect ratio, so if your monitor is 1920, 1080, but you try and set a 1024,768 resolution, the graphics screen will not reach across the whole screen. The graphics screen will be displayed centered on the monitor, hence the black borders on the sides.

SetVirtualResolution():
AGK will map coordinates specified in the graphics command between the virtual resolution and the actual resolution. So if your window is set to 1024, 768, but your virtual resolution is 800, 600. Then coordinates 800,600 will map to 1024, 768 and 400,300 will map to 512, 384. This way you can write your game using a single coordinate system and it will look the same regardless of the actual resolution used.

SetScissor()
This sets the clipping range of your graphics screen. The first two numbers is the coordinates of the upper left corner, and the next two numbers are the coordinates of the lower right. In your example (0,0,1,1) will limit the rendering to a single pixel in the upper left corner. To restrict the rendering to the actual graphics area, you would use SetScissor(0,0,virtualWidth,virtualHeight). Using 0,0,0,0 is a special case meaning no clipping so you can utilize the entire screen. To render to the left and top, you can use negative coordinates, and to render to the right and bottom, use coordiantes greater than your virtual resolution. You can find the actual usable coordinates by using GetScreenBoundsLeft(), GetScreenBoundsRight(), GetScreenBoundsTop(), and GetScreenBoundsBottom()

This might seem like a strange system to use, but it does give some advantages. Your program will run on a much wider number of devices, no crashes if the device doesn't support your chosen resolution. Windowed programs can be resized by the user and your program will automatically scale, keeping the proper aspect ratio so graphics don't end up squashed. Crashes in fullscreen doesn't result in an unusable system. EVer have a fullscreen Blitz program crash and you can't restore the desktop? With AppGameKit, just Alt-Tab back to the desktop.

If you are ever unclear about what a command does, you can just type the command into the editor, then press F1 to bring up the docs for that command.
KayDee
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location:
Posted: 8th Apr 2020 04:12
Thanks to Raven & TomToad

Both of these posts were extremely enlightening.


end of line.

Login to post a reply

Server time is: 2024-04-26 17:06:02
Your offset time is: 2024-04-26 17:06:02