Jump to content

  • Log In with Google      Sign In   
  • Create Account


scaling sprites


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 26 January 2013 - 12:25 PM

I remember playing F.E.A.R. when it came out, at the time this was not an issue but later when I was able to play at higher resolutions, I noticed that GUI was smaller and smaller on higher resolutions and fonts were scaled up (they were TTF font (I think) after all). I didn't notice this in other games, and I know there is a way to avoid this. How exactly should this be handled regardless of game? If I have a sprite that that has certain dimensions how can I make it cover same amount of screen on all screen resolutions?



Sponsor:

#2 FLeBlanc   Crossbones+   -  Reputation: 3101

Like
0Likes
Like

Posted 26 January 2013 - 12:28 PM

Either scale it, or provide multiple versions for the different resolutions. Or use vector art (which is how a font is able to scale) for which scaling is well-supported.



#3 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 26 January 2013 - 12:36 PM

When rescaling sprites can lose fidelity, I don't want that. Which format can be used for vector art so it is usable with OpenGL or SDL?



#4 Servant of the Lord   Crossbones+   -  Reputation: 18735

Like
5Likes
Like

Posted 26 January 2013 - 01:25 PM

I've never dealt with vector images myself, but here's what little I understand: .svg is the most common and popular vector art format.

 

SDL doesn't have knowledge of vector graphics. I don't think OpenGL natively does either. OpenVG is an API for hardware accelerated vector graphics. 

But that's not really what you want anyway, because SDL doesn't need to know about vector graphics.

 

Imagine this: You have your GUI images in vector graphics.

Your game is loaded, your resolution is set to 1920x1280, so you use your vector graphics to generate bitmap images of the sizes you want. Then, you give the generated pixel data to SDL and SDL draws them like normal. The user resizes the game to 1024x768, and you use your vector graphics to generate bitmaps at a new size that you then pass to SDL. You don't need to generate the bitmaps every frame, just once whenever you want a new size.

 

So, you'll want a third-party library that is independent of drawing graphics, and doesn't require a window, to load a vector image and generate pixel data at various sizes for you. Something small, compact, and simple that you can plug easily into your existing program.

 

Which library that would be, I'm not sure. Perhaps librsvg, but that has two other dependencies (libxml and Cairo, and I'm not sure how hefty Cairo is). There's an outdated third-party SDL_svg library, but it's pretty old. Maybe download that and see how it works? I just stumbled across AGG, perhaps that might work.

 

You'd have to deal with resizing text too, if your GUI text is dynamic, but that's a separate topic and you're probably using SDL_ttf anyway.


Edited by Servant of the Lord, 26 January 2013 - 01:28 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 Khatharr   Crossbones+   -  Reputation: 2972

Like
1Likes
Like

Posted 26 January 2013 - 09:04 PM

There are several methods for dealing with sprite scaling (mipmapping and filtering immediately spring to mind).

 

Switching to vector graphics is a pretty significant change in your graphics design. Just be aware that it's not your only option.


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#6 rishflab   Members   -  Reputation: 109

Like
0Likes
Like

Posted 26 January 2013 - 10:17 PM

I have a similar question to OP ( see my thread http://www.gamedev.net/topic/637864-scaling-2d-bitmaps-for-multiple-resolution-support/)

 

What happens if I draw all my sprites at really high resolution and scale them down to fit all the required resolutions? Will this result in negative effects on image quality?


Edited by rishflab, 26 January 2013 - 10:23 PM.


#7 Servant of the Lord   Crossbones+   -  Reputation: 18735

Like
0Likes
Like

Posted 26 January 2013 - 10:42 PM

Sometimes, yes - depending on the details of the image itself. Also, it depends on what kind of scaling algorithm you use.

If it's a simple GUI element, it probably won't look too bad.

 

You could always make a high res one, save it. Resize it using a good algorithm in your image editor, manually correct any mistakes, save it as a Mid-res version. Repeat for the low-res one. Then just use the closest match, and add more versions between high, mid, and low, if needed.

 

But at that point, you might as well use a vector image - and use your vector image editor to generate the various resolutions of the image for you, and then ship the various images, but not the vector image itself, with your program.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#8 Aldacron   GDNet+   -  Reputation: 3149

Like
0Likes
Like

Posted 27 January 2013 - 05:07 AM

FYI, if you are using the rendering API in SDL2, there is a function SDL_RenderSetLogicalSize which allows you to program to a fixed resolution no matter the resolution of the display window. The entire output is scaled by the hardware (assuming the D3D or OpenGL renderer). This is a painless alternative to handling SVGs. I'm using it to good effect in a game I'm working on right now. It's a low-res game, so I'm rendering to an 800x600 logical size. For high-res graphics, you'd want to render to a higher logical resolution that would then be scaled down. I don't know for sure what sort of effect it would have on quality in that case, but it would certainly be worth looking into before going all SVG and scaling individual images.

#9 proanim   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2013 - 09:37 AM

SDL2 isn't ready yet there is some better stuff in it, but I would still like to avoid it until it is officially released. I can scale my sprites using streching which appears to have good effect when downscaling. So, any advice on how can I calculate how much I should resize the sprite depending on screen resolution, so it covers 'the same' amount of screen? The problem that I currently see is that I can't exactly tell if the sprite is scaled up enough. I am currently testing with 640x480 and 800x600 resolutions.



#10 Servant of the Lord   Crossbones+   -  Reputation: 18735

Like
2Likes
Like

Posted 27 January 2013 - 11:59 AM


FYI, if you are using the rendering API in SDL2, there is a function SDL_RenderSetLogicalSize which allows you to program to a fixed resolution no matter the resolution of the display window. The entire output is scaled by the hardware (assuming the D3D or OpenGL renderer). This is a painless alternative to handling SVGs. I'm using it to good effect in a game I'm working on right now. It's a low-res game, so I'm rendering to an 800x600 logical size. For high-res graphics, you'd want to render to a higher logical resolution that would then be scaled down. I don't know for sure what sort of effect it would have on quality in that case, but it would certainly be worth looking into before going all SVG and scaling individual images.

 

I'm not familiar with SDL2, but SFML has something similar (using 'views'), and is an awesome by-product of the nature of the 3D APIs which SDL2 and SFML are built upon.

While nice and useful for most things (the game content itself)... if you use it with your GUI, still have to take into account the *ratio* of the resolution, or your GUI can get stretched in ways you don't want.

 

SDL2 isn't ready yet there is some better stuff in it, but I would still like to avoid it until it is officially released. I can scale my sprites using streching which appears to have good effect when downscaling. So, any advice on how can I calculate how much I should resize the sprite depending on screen resolution, so it covers 'the same' amount of screen? The problem that I currently see is that I can't exactly tell if the sprite is scaled up enough. I am currently testing with 640x480 and 800x600 resolutions.

 

The cheap and easy way is to use percentages (well, 0.0 to 1.0). If the GUI element is 20 pixels of a 800 pixel wide screen, that's 0.025f the screen. So for a 1024 wide screen, you might resize it to 26 pixels wide (1024 * 0.025 = 25.6). Bu you also want to keep the the element from being stretched out of it's shape, so you need to calculate the width of the element relative to it's height, then multiply.

float guiElementRatio = (NormalElementHeight / NormalElementWidth);
float elementRelativeWidth = (NormalElementWidth / NormalScreenWidth);

int currentElementWidth = (CurrentScreenWidth * elementRelativeWidth);
int currentElementHeight = (currentElementWidth * guiElementRatio);

I was resizing the elements based on the width of the screen - in retrospect, resizing the elements based off of the height of the screen is a better solution.

 

Anyway, you can do the same with the element's position. As mentioned, this is the cheap and easy way - a more difficult but superior solutions also have the elements morphing in the content they show, as more screen space becomes available or scarcer.


Edited by Servant of the Lord, 27 January 2013 - 11:59 AM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#11 Aldacron   GDNet+   -  Reputation: 3149

Like
1Likes
Like

Posted 27 January 2013 - 07:17 PM

While nice and useful for most things (the game content itself)... if you use it with your GUI, still have to take into account the *ratio* of the resolution, or your GUI can get stretched in ways you don't want.

SDL's implementation will also take care of this for you. From the function documentation:

This function uses the viewport and scaling functionality to allow a fixed logical
resolution for rendering, regardless of the actual output resolution. If the actual
output resolution doesn't have the same aspect ratio the output rendering will be
centered within the output display.

As I said, I'm using it to good effect.

SDL2 isn't ready yet there is some better stuff in it, but I would still like to avoid it until it is officially released.

It's perfectly usable now. I've been using it for just about a year without any hassle at all. There's an occasional API change, but nothing drastic or difficult to keep up with. I can't imagine going back to 1.2. Do what works for you now, but I would definitely recommend giving SDL 2 a look over 1.2 for your next project whether it's officially released or not.

I can scale my sprites using streching which appears to have good effect when downscaling. So, any advice on how can I calculate how much I should resize the sprite depending on screen resolution, so it covers 'the same' amount of screen? The problem that I currently see is that I can't exactly tell if the sprite is scaled up enough. I am currently testing with 640x480 and 800x600 resolutions.

One way is to work with percentages. You pick a target resolution and the sprite size you want to show at that resolution becomes your 100% base. Then, as you scale the resolution down, you scale the sprite by a percentage relative to difference in resolutions. You'll have to account for aspect ratio in your calculation to avoid stretching.

Another approach is to preconfigure a scale factor for different resolutions. Implement some test code to manually cycle through different scale factors at different resolutions to see which look best. Save those off into an array/config file/script and at game startup or on resolution change, pick the appropriate value and use it as a global scale factor. If taking this route, you'll likely want to combine it with the percentage-based approach to cover the case when the user configures a resolution you didn't anticipate.

#12 Tispe   Members   -  Reputation: 1031

Like
0Likes
Like

Posted 29 January 2013 - 02:47 AM

You can render UI to a texture. So you can have a UI texture 1024x1024 in size regardless of the size of the rendered scene. Your UI will then be downsampled to fit a scene less then 1024x1024 in size and upsampled to a scene larger then 1024x1024 in size.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS