# Sprite/Texture Scaling After Resolution Change

2 replies to this topic

### #1Annihilator

New Member

• Members
• 10 posts

Posted 07 January 2012 - 03:15 AM

Hi, can anyone give an advice on how to scale Sprites or Textures when window resolution is changed?
I am using glOrtho(); in OpenGL, and I have my original sprites about 90% larder in size originally, when i render them
in my test window, which is 800x600, i Scale them down to 10% of the size so they look nice in s small window, which they do.

I was wondering, when there is a 2D glOrtho set up, how should i go about scaling the sprites when changing the resolution?
Is it really done in 2D games? Or should, whoever has higher resolution, see more of the world (map)?

At the moment, i have tried one trick, my lowest resolution is 800 x 600. At this resolution sprites are scaled down to 10% of the original size.
When i change the resolution, i re-calculate Scalar, and re-scale sprites according to this new Scalar variable.

// As a minimum res will be 800x600;
float Scalar = getScreenWidth() / 800;
// 800 width = 10% of the original size.
resScalar = -(90 / resScalar);
// Scale the ship sprite
ship->Scale(resScalar);


Here it is at 800x600:

Here it is at 1920x1200

So as you can see, it kind works good.

* I was wondering, how would you go about background textures?
If we are talking about Tile Based approach? If tiles are fixed size, you cant re-scale textures in them? right?

* And one other thing, what resolution should all the sprites be? All in the same resolution which is much bigger then they appear
in the game, so they can be scaled up and down in game as i need ?

Please, whoever did that before, could you give some advice on what to do with the sprites (textures) when resolution
has been changed. Thanks.
Technical Director, Engine Programmer.
ANN-Tech. Team.

http://www.ann-tech.com

### #2Stainless

Member

• Members
• 582 posts
• LocationSouthampton

Posted 07 January 2012 - 10:08 AM

Your display code should be independent of screen resolution.

Just set up a projection matrix that is the size you want, and then render your scene at that resolution.

If the view port is larger than your display code expects, the pixels will look bigger, if it is smaller, they will be blended together.

Are you trying to use different graphics based on view port size?

### #3TheNut

Senior Member

• Moderators
• 1701 posts
• LocationCyberspace

Posted 07 January 2012 - 02:37 PM

I think his intent is to change resolution and display a higher quality sprite, which should take up the same percentage of pixels as a lower quality sprite in a lower resolution. Since he's stretching the image, Stainless answer seems logical. Just set the viewport to match the screen size and leave your projection matrix fixed. The GPU will automatically stretch your graphics. Some 2D games take this approach. Another more common approach is to change both the viewport and projection matrix to match the screen size, which makes the sprites smaller (quality is maintained), but the gamer sees more of the world.

If your intent is to display higher quality sprites at a different resolution, then you need to provide a new set of sprites catered for that resolution, which will automatically size the sprites to the view.

Annihilator said:

I was wondering, how would you go about background textures? And one other thing, what resolution should all the sprites be?

- This all depends on what your end goal is. In an ideal world, you would simply cater to the highest possible resolution and then downscale as needed for lower resolutions. This relaxes the requirements on your artists, but comes at a cost. First and foremost, the obvious reason for playing a game in a lower resolution is because the target machine is inadequately capable of running the game at a higher resolution. By loading higher quality textures, you're consuming more memory than what the target machine might actually have and the performance of your game can suffer. Also, not all rescaled graphics look good. Sometimes an image needs special treatment to avoid quality loss. It's a tradeoff for keeping things simple.
http://www.nutty.ca - Being a nut has its advantages.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users