Scaling Graphics for different Resolutions
Members - Reputation: 205
Posted 22 August 2012 - 02:06 PM
My question is this:
What is the best way to allow the game to run on different resolutions?
The only option I see is to scale the graphics uniformly and allow the screen to show less.
ie. On a higher resolution computer, scale everything up uniformly so the backgrounds either fit perfectly or are larger than the screen.
Any help is much appreciated,
"Other than that, I have no opinion."
My Blog - Check it Out
Crossbones+ - Reputation: 9881
Posted 22 August 2012 - 09:32 PM
You're not supposed to render at one resolution and then resize as needed, you should get the screen resolution at the start of the program (or better yet, via some kind of configuration option) and render at that resolution. In 3D games you do this by abstracting resolution information away by dividing all widths by the total screen width and all heights by the total screen height (so you then have coordinates between 0 and 1) and just using the aspect ratio to render.
YMMV depending on your answer to my question.
Also, it's possible to resize stuff like textures to an arbitrary resolution, by interpolating (but there should be a function available in whatever library you use to render to do this for you, probably along the lines of StretchBlt or something). The new resolution doesn't have to be a multiple of the old one for it to work.
The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.
- Pessimal Algorithms and Simplexity Analysis
Members - Reputation: 986
Posted 22 August 2012 - 09:46 PM
My preference for 2D side scrollers and such is to work in low native resolution (like 320x240), and scale up by 2x, 3x, 4x, etc. until it's as big as can fit on the screen, and just leave the border black (unless it's in a window and then you don't need a border).
Another option for 2D games is to have a larger "viewport" in high resolution... so you can just see more of the map on screen. But it's annoying as a designer not to have control over how far ahead the player can see, or how tall the screen is relative to a background (for doing levels with no vertical camera movement).
For single screen games like tetris, you can do the integer scale up thing, but have a border image instead of just black. The border image will get chopped off at the edges of the screen depending on how well matched the resolutions are, but it's just there to fill space so who cares if you can't see all of it.
For 3D or vector graphics games, you can do actual resolution independence. Make HUD graphics where they position relative to the corners of the screen rather than spanning from one side to the other, and possibly use different sized fonts for text boxes in different resolutions so they look consistent.
Members - Reputation: 259
Posted 23 August 2012 - 10:28 AM
If you're using SDL (1.2 probably), then render to a fixed-size Surface then later stretch that surface to fit SDL's main screen surface (you may need SDL_gfx for this)