Adjusting display routines for screen sizes

BlitzMax Forums/BlitzMax Beginners Area/Adjusting display routines for screen sizes

Xerra(Posted 2013) [#1]
I've been hard coding stuff to just work on whatever screen display I've got for years now and it's a bad habbit I want to get out of. Whenever I run anything I've written on a different machine, it will likely look odd as that machine could be using a different resolution.

What I'm looking at is some kind of code example to show the screen size being taken into account and the display routines adjusted accordingly.

So if i'm running at 640, 480 for example then

DrawText ("Top Scores!",320,240)

is going to be centre of the screen.

But when the screen mode is 800,600 then it's going to be more closer to the left corner which won't do.

I'm thinking based on how web sites often use a percentage marker to cover for different display sizes so the sites will be laid out close to identical but with smaller text if the display resolution is a bit higher.

But I'm struggling to figure out a system of how to display screen text and objects in blitz a similar way, allowing for the fact that the object size could now be smaller as well as ensuring text goes to the same location on screen regardless of the display width/height.

Hope this makes sense. Anyone able to show me how they do this if i have the screen width set in width.int and screen height set in height.int for example ?


GfK(Posted 2013) [#2]
Read up on SetVirtualResolution. I was going to link to it on this site, but it doesn't seem to be documented here.

Anyway, the idea is that you do this:
Graphics 800,600
SetVirtualResolution(640,480)

Drawing some text at 320,240 would then still be at the centre of the screen, in any graphics mode you choose (because your game logic is always running in 640x480).


ImaginaryHuman(Posted 2013) [#3]
Using a virtual resolution means the camera is using a custom projection matrix, which means possibly sprites etc will be sampled ie resized to fit the screen, which does mean you will lose the 1:1 pixel:texel ration of `pixel perfect` sprites which you might not want.. unless you're okay with that. The only real solution to that though is to start with big sprites and let them scale down, maybe with a bit of sharpening, or make a set of sprites for each resolution.