Sign in to follow this  

[C++] Aspect ratio correction with sprites

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to develop a 2D game that uses a 4:3 aspect ratio on a 16:9 monitor, so everything is ugly. Since the transformation pipeline is skipped entirely when rendering sprites, can I apply aspect ratio correction to them?

Share this post


Link to post
Share on other sites
I'm not sure I understand you. Shouldn't you rather set your monitor to a different mode so that it won't stretch the screen but add black areas to the left and right instead?
Or do you want your game to support both 4:3 and widescreen (16:9 or 16:10 which is more common for monitors than the TV 16:9, I think) resolutions? If yes, then you simply have to render more on the screen for wide resolutions in 2D games, there won't be any aspect ratio correction.
For example - imagine a 160x160 pixels sprite.
Case #1 - 4:3 monitor, resolution 1600x1200 - the sprite will be square, 160x160 pixels and 10 of them will fit the screen horizontally.
Case #2 - 16:10 monitor, resolution 1920x1200 - the sprite will be again square of course, 160x160 pixels and 12 of them will fit the screen horizontally.
Case #3 - 16:10 monitor, resolution 1600x1200 - depends on how do you set your MONITOR to display the "unnatural" resolution.



But maybe I really just don't understand you ;)

Share this post


Link to post
Share on other sites
To be honest, I was having trouble visualizing my problem myself. Aspect ratio came to mind simply because my game was resampling a 4:3 frame to a 16:9 monitor, and horizontal distortion was noticeable. It didn't initially occur to me that I was still working with sprites of the same size. (believe it or not...)

Thank you for trying to address my question, but I am grasping the perspective I need to now.

Share this post


Link to post
Share on other sites
Are your sprites stretched?

If so, I had this problem, too, but I was able to solve it.
You need to do a ScaleTransform to set the Sprite size to the
Screen size.

Do it like this:


D3DX10_SPRITE spriteInfo;

D3DXVECTOR2 ScaleFix; //Fixes the Scale-Problem

ScaleFix.x=(float)((float)1/((float)ScreenSize->x/2))*ActiveTexture->Info.Width; //Set to the ScreenSize
ScaleFix.y=(float)((float)1/((float)ScreenSize->y/2))*ActiveTexture->Info.Height;

ScaleFix.x*=Scale.x; //Multiply with the normal Sprite scale
ScaleFix.y*=Scale.y;

D3DXVECTOR2 rp; //RenderPosition

rp=Pos; //Pos=Original Position

rp.x/=ScaleFix.x; //Divide through the ScaleFix
rp.y/=ScaleFix.y;

D3DXMatrixTranslation(&spriteInfo.matWorld, rp.x, rp.y, 1.0f); //Translate the sprite
D3DXMatrixScaling(&spriteInfo.matWorld,Scale.x,Scale.y,0); //Apply scale


//Do rendering

Share this post


Link to post
Share on other sites

This topic is 2853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this