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 / Some resolutions causes truncation

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 6th Jun 2018 16:38
Hello ( = I have some stretching issues when I use a screen resolution of 1440x900, my game is designed for 1280x720 on Windows PCs. I have some fixed sprites on screen, these are fine, but the images that I pull through the backbuffer (SetRenderToImage) gets truncated. I use SetWindowSize(1280,720,1) and SetVirtualResolution(1280,720). I have also tried SetScreenResolution(1280,720) but that will revert the game from fullscreen back to a window of that size. My current GFX that I am doing this on is a Geforce GT610. Does anybody know what I can do? I have previously had a lot of SetVirtualResolution in the main loop to change back and forth between virtual resolutions whenever I needed to render to an image or update text, but this also comes with an impact on performance so I would like to avoid that.
13/0
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Jun 2018 18:46 Edited at: 6th Jun 2018 19:06
This is covered well in the guide for displays
https://www.appgamekit.com/documentation/guides/0_display.htm

1280x720 is a 1.78 aspect ratio
1440x900 is a 1.6 aspect ratio so this will mean black bars (ANY resolution that isnt an aspect ratio of 1.78 will result in this if your manually setting your resolution)

You can use SetDisplayAspect() and the percentage system as this can make your apps/games device and resolution independant as the image is then stretched to the fullscreen no matter what. Using SetDisplayAspect(-1) will fill the screen as it uses the hardware Width and height values.

EDIT:

I almost forgot - Also see SetScissor(0,0,0,0) as this does similar to the above and fills the screen
https://www.appgamekit.com/documentation/tips.html#blackborders
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 7th Jun 2018 08:53
I just tried using the percentage system, it messes up my game. When I use virtual resolution and a fullscreen window, most graphics are fine and there are black borders at the top and the bottom when using 1440x900 which is fine, then the game isn't stretched or truncated, except for two full-screen sprites. The two fullscreen sprites are the bottom layer (floors) and then there is another sprite on top of that (walls, tables, furniture etc.). These two fullscreen sprites are created during the game whenever the game loads a map, and they are modified every time a player shoots (the game draws blood, bullet casings etc. on the bottom sprite during a match). The problem is that when I use SetRenderToImage on an image, that image will be truncated, and I think this is because of the backbuffer size. I will attach an image, notice the floor image, it got black borders within the game window, the entire game also got black borders, you can see that the "monitor" image is not truncated or stretched and got black borders, but the floor got even bigger black borders. I can create a small snippet that can maybe reproduce this if you set your resolution to the same. I have experimented with coming up with an algorithm that can set the right size for the sprite so it will get stretched to the right size. If I set the sprite to a height of 800 pixels and offsetting it -40 on the Y axis, it fits nearly perfect.
13/0

Attachments

Login to view attachments
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 7th Jun 2018 10:54
I have made a small snippet that shows the error on a resolution of 1440x900. If you set it to setting 1 it shows correctly but this depends on changing virtual resolution many times during game main loop which has an impact on performance, if you set it to 2 it will truncate the image drawn to but you only set virtual resolution once.
13/0

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 7th Jun 2018 21:53 Edited at: 7th Jun 2018 21:58
Simply put...if your virtual resolution aspect ratio doesnt match the render target aspect ratio (Thats EITHER the screen OR a render image) then it results in black bars. So you can end up with black bars on a rendered image....which then gets rendered on a screen inside black bars so you get the effect compounded... x2 .Double the effect...if you know what i mean.

Its also up to you to ensure your sprite which is displaying the render target is the correct size too.

This isnt a bug as far as I can see...its how it should be and I dont see a problem with it. Multiple resolutions works fine in AppGameKit but different aspects make for problems like this....especially when you are rendering to an image so it doubles the effect of black bars within black bars.

If you simply use this
SetVirtualResolution( 1280, 720 ) // doesn't have to match the window or fullscreen resolution
SetDisplayAspect(-1)


Then NEVER change the virtual resolution again... you shouldn't have the issue. The final game will always fill the screen and any render target should be 1280x720 too. your aspect will be awful on a phone in portrait mode though so youmay want to disable it.


Lastly....switching the virtual reolution wont affect performance much (it shouldnt - I quickly tested it and it barely touched my frametrate). All it does is recompute the projection matrix for sprites ....it doesnt actually re position them all or anything. There screen position is always worked out by the graphics card in everyframe anyway so its no real performance hit to recompute "AGK_ortho" a few times.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 8th Jun 2018 09:19 Edited at: 8th Jun 2018 09:28
Quote: "SetVirtualResolution( 1280, 720 ) // doesn't have to match the window or fullscreen resolution
SetDisplayAspect(-1)"

That doesn't work either. I have attached an image of the result. I only set virtual resolution at the beginning of the app.

EDIT: If you fill the image with the A button in my snippet and set display aspect to -1 you can also see the black lines there.
13/0

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 8th Jun 2018 11:38 Edited at: 8th Jun 2018 11:59
It works fine on mine at both 1280x720 and at 1440x900 as long as the virtual resolution is set correctly. Ive a game running this on 3 monitor sizes and it does work fine and displays using the full screen. Im wondering what else your doing or if its even a graphics driver issue (thats un likely)?

Display your sprite used for background image on the screen in the top left corner (say 200x200 pixels) and check it for black lines...if so then your not rendering the back properly at the correct resolution or aspect.

EDIT: What happens if you run this?? Your "A" filed image works fine AND you can choose whether you have black lines in the final render OR not.

Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 8th Jun 2018 13:39
I have tried changing window size as suggested in your snippet but I still get horizontal black lines between the A images. The screen should be filled solid. I will attach two screenshots, the one with bars is with a 1440x900 resolution and the other is with 1920x1080. I have tried it on an Intel HD 4600 and a Geforce GT610, it is the same on both. I really appreciate your help here! Is there anything I can do in return? Do you have a release I can play?
13/0

Attachments

Login to view attachments
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 8th Jun 2018 13:57 Edited at: 8th Jun 2018 14:01
Thats because your sprite is just 14 pixels high and the step in your code is 16

Add SetSpriteSize(a_button_sprite,16,16)

This is a consequence of having a different screen aspect ratio to that of the virtual resolution.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 12th Jun 2018 11:54
I have made it work so that I can draw on an image that is 1280x720 by setting the virtual resolution to GetMaxDeviceWidth() and GetMaxDeviceHeight() before drawing on the image and then setting virtual resolution back to 1280x720 before doing anything else, but all text that is edited after this will change size. I have added an image, the text on the left have been altered, the one on the right has not.
13/0

Attachments

Login to view attachments
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 12th Jun 2018 12:01
Nevermind the last post, I forgot to set render back to screen after editing an image ( = Thanks for all your help and time, I am back to where I started, changing virtual resolution several times throughout the main loop, but in this process we've had here I've found a simpler way to do it so it will happen fewer times ( =
13/0
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 13th Jun 2018 21:18
Yeah, im afraid that changing the virtual resolution appears to be the only way to keep on top of the aspect ratio issue.

At first I thought it was fairly simple but it is much harder than I expected when rendering to images to stay in control of the correct aspect ratio rendering without resorting to a virtual resolution.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th Jun 2018 08:57
I would like this to be simplified, I have spent a lot of time getting different aspect ratio to work right when drawing to images. I think it is because of the backbuffer size, I tried setting resolution but it seems to have no effect.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 18th Jun 2018 18:15
So I got the different aspect ratios working, but now, the images created for floors and walls appear either blurry or way-off pixelated, and this is only true for the playfield images which are the ones created during run-time and these are also the images I need to edit during the game where I use this SetVirtualResolution trick. I have other sprites created from the same tiles used as destructible doors and objects, these appear crisp and correct. These sprites should not be affected by virtual resolution switches. I have tried SetImageMagFilter and SetImageMinFilter, they make them either blurry or way-off pixelated, it looks very bad together with the other sprites that are still crisp. I have attached an image.
13/0

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-28 23:31:56
Your offset time is: 2024-03-28 23:31:56