shadowartist201 / TKA-PC-Port

A Windows port of Techno Kitten Adventure.
https://shadowartist201.blogspot.com/
32 stars 3 forks source link

[Android] Upscaling issue during levels #9

Closed shadowartist201 closed 9 months ago

shadowartist201 commented 10 months ago

Introduced new feature that enabled upscaling in d3da608. Appears to work well for all menus with a static background (opening menu, main menu, options menu) but reverts to the original scale when level choreography is playing (kitten select, general gameplay, pause menu). Unknown why this is happening. Maybe something to do with how the star tunnel is drawn?

Tested on Samsung Galaxy Fold 5

Screenshot_20230820_020314 Screenshot_20230820_020340

shadowartist201 commented 9 months ago

Fixed the scaling in 4a33c8b, but going in-level still causes issues. Screenshot_20230911_223401 Screenshot_20230911_223443

shadowartist201 commented 9 months ago

In this case, Graphics.Viewport is switching from [312, 0, 1607, 904] (center) to [0, 0, 2231, 904] (top left). I tracked down the moment it switches when graphicsDevice.SetRenderTarget(null) is called in Camera.Draw().

Commenting out SetRenderTarget() doesn't work. It looks like it needs to be null.

[Error in swap buffers] System.InvalidOperationException: Cannot call Present when a render target is active.
[Error in swap buffers]    at Microsoft.Xna.Framework.Graphics.GraphicsDevice.Present()
[Error in swap buffers]    at Microsoft.Xna.Framework.AndroidGamePlatform.Present()
shadowartist201 commented 9 months ago

If we look at the drawing code, maybe we can get a better idea.

graphicsDevice.Clear(Color.White);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Resolution.getTransformationMatrix());
spriteBatch.Draw((Texture2D)renderTarget, Camera.position_, (Rectangle?)null, Camera.color_, Camera.rotation_, new Vector2(640f, 360f), Camera.scale_, Camera.spriteEffect_, 0f);
spriteBatch.End();

The renderTarget (1280x720) is being drawn at position (640,360) and origin (640,360), which should be the middle of the (virtual) screen. Rotation is 0, scale is 1, and spriteEffect = none. I assume that the transformation matrix in Resolution is being applied to renderTarget, but what would that look like?

Game1.Draw() draws items specifically (text, icons, etc). Maybe that's the difference? Using a renderTarget causes things to break?

shadowartist201 commented 9 months ago

Fixed resolution by moving things around in Camera.Draw(), see commit c619bad7