Advertisement

Scaling images for different displays

Started by May 15, 2015 02:17 AM
5 comments, last by Servant of the Lord 9 years, 7 months ago

Hey, so I'm well underway on the logic of my (2d) game using SDL 2, but I've run into a snag.

I want the game to look nice, so I'm going to make images 1920 x 1080 display and want to just scale it down for different devices/monitors. I've looked around and have not found an efficient way to do this on SDL 2. I just find it hard to believe that it wouldn't have a decent method for scaling textures.

If someone could give me some insight on how rendering textures to different resolutions/screen sizes generally works, that'd be awesome.

Also, I've considered just porting everything over to openGL and starting over, what do you think?

Thanks in advance.

edit: ok I found a function SDL_RenderSetLogicalSize which could do what I want, I'm tinkering with it now.

edit2: This function helped but I still can't scale down in resolution.

When I changed my resolution and went full screen, the entire image wasn't displayed.

Look at soft stretching



http://lazyfoo.net/tutorials/SDL/05_optimized_surface_loading_and_soft_stretching/index.php
Advertisement
You are expecting the api to do too much. As long as there is efficient support for scaled blits, you can create your own system to map from a virtual to physical resolution.

Super high resolution images that get scaled DOWN, can look almost as bad as super low resolution images that get scaled UP (depending on the art style - some styles are more tolerant to resizing than others). The best appearance is the appearance that most closely matches what size you are rendering at.

So, developers usually manually scale their images to various likely sizes using higher-quality (but slower) scaling algorithms, and then choose the closest match at run-time. "manually" can include doing this automatically using batch files or whatever. Sometimes this high-quality scaling happens during game startup, or similar.

In 3D graphics, pre-scaling the textures is called 'mip mapping'. I'm not sure if there is a more specific term for 2D sprite pre-scaling.

There is plenty of 2d UI which gets scaled.. Like most scaleform ui. SC2 2d Menu and HUD UI for example, and other blizzard 2d hud UI.

Lately, it is most common to do this scaling using 3d apis, because the hardware is really good at filtered scaling.

There are several concerns here.

One is the aspect ratio, the is other is the number of dots.

There are many different aspect ratios, like 4:3, 5:4, 16:10, 16:9. The widescreen 16:9 ratio is currently most common due to the ultra-cheap displays that use it, and because many of these displays match the 1080p movie resolution so the common population assume it is the best.

Within a single aspect ratio it is not too difficult to change the size. As an easy approach you can just set your screen to be a virtual viewport from zero to 1, or from +1 to -1, or whatever transformation you need. Then if you are rendering at 16:9 (or whatever aspect ratio you use) it doesn't matter what the screen resolution is, 1920x1080, 1600x900, 1024x576, 5120x2880, the screen fills with the same information in the same place but with more or fewer pixels. Of course you can also choose to provide more information to those with more pixels by keeping the pixel level content the same.

Changing to different aspect ratios can be more tricky. You can stretch your screen, but that tends to look odd to players who move between machines. You can add or remove content in various dimensions, which can give an advantage to those with monitors like a 16:10 or 5:4 ratio. You can add black bars for a letterboxing effect, but that can really annoy people who have different monitor resolutions.

A more complex system is able to handle various layouts based on screen metrics and user settings. A common path is to place UI elements extending out from each of the four corners, with a scale that is appropriate so the targets are easy to hit with the mouse but don't get in the way of gameplay.

There are pros and cons to each set of choices.

Higher resolution displays naturally can display more information than lower resolutions. If you've got players running at 800x600 playing next to someone with a display at 5120x2880, the second player has about 30 times more pixels available. The choices for aspect ratio and screen size handling is often an annoyance to single player games, but it can make a critical difference in multiplayer games. Do you provide the same information, perhaps just with higher detailed textures? Do you provide different information? Do you add black bars or distort the images for aspect ratios you don't support?

There is no single best answer for everyone. There are many options and each may or may not be appropriate for a given game.

Advertisement

There is plenty of 2d UI which gets scaled.. Like most scaleform ui. SC2 2d Menu and HUD UI for example, and other blizzard 2d hud UI.

Yes, some scaling is usually necessary, but the farther you are (lower or higher res) from the resolution you are scaling to, the worse it'll look. The point is to minimize the amount of scaling by choosing the nearest pre-made resolution that you have available. Depending on what UI element is being scaled - some elements and some styles are more tolerable to scaling than others. Scaling down does look better than scaling up, but it's better still to have a resolution that already matches what you want.

Things like icons and text especially scale poorly. Anything where sharp detail is important should be scaled as little as possible - scaling down creates blurriness, scaling up requires detail that is no longer available.

An alternative is using vector images, which can use input to generate the image for you at whatever precise resolution you want.

This topic is closed to new replies.

Advertisement