Different screen resolutions in a 2D game

Started by
6 comments, last by marvel_magnum 12 years, 2 months ago
My problem is handling different screen resolutions. I want to draw a scene of the same size(1024,768) on different screen resolutions. I don't know what technique is usually used for doing this in 2D games.

To see what I want to do look at the screenshots below from a game called Facewound. Here are screenshots when running the game in 640x480 and 1024x768 window size. It is obviously the same scene, and if we count the tiles (32x32), we see that the original scene is 1024 pixels wide and it is somehow rendered to fit on just 640x480 window.

In my game if I change the screen resolution, the size of the scene that will be rendered depends on the size of the bacbuffer.So if it is 640x480, it just renders the upper left corner of the size 640x480. But I want the whole 1024x768 be rendered on 640x480 and not just the upper left part.

I am using DirectX and ID3DXSprite object to render sprites. All, I need is the idea/principle how stuff like this are made, not the code.

640x480
tOdNy.jpg

1024x768
Va6xw.jpg
Advertisement
You can render the backbuffer in the optimal resolution of your game (in your case 1024x768) and then use IDirect3DDevice9::StretchRect() method to scale the entire frame according your output resolution.

I have never done this myself, but it should work since both your backbuffer and your primary buffer are Direct3D surfaces. happy.png

You can render the backbuffer in the optimal resolution of your game (in your case 1024x768) and then use IDirect3DDevice9::StretchRect() method to scale the entire frame according your output resolution.


But, how will I render my 1024x768 scene, if my backbuffer/screen/window size is just 640x480 ? The scene outside 640x480 won't be rendered at all. That is my problem, rendering a scene bigger than the screen size.
Can't stretch be used to down-res as well? So, you blit to your back buffer that's 1024x768, but when you blit to the final, on-screen buffer, it is 640x480, and it gets scaledd down on the final buffer.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

You need to setup your projection matrix correctly. I've forgotten how to do this exactly, it's been awhile.

IIRC, you need to setup your projection matrix in your own units, rather than pixels. Instead of specifying 640x480, you specify, for example 4.0x3.0, and everything else in your game (units movement, distance calculation, etc) must conform to that measurement you've set. That means a unit that moves at 4.0/sec will move across the screen in one second.

It becomes resolution independent. If your game is run on 1440x900, which as 1.6 aspect ratio, your game sprites will appear stretched.
IDirect3DDevice9::StretchRect() method can be used to scale to both up-res and down-res. So you can stretch a 1024x768 screen to 640x480 or 1920x1080 or to any resolution and it will scale appropriately.


you need to setup your projection matrix in your own units, rather than pixels. Instead of specifying 640x480, you specify, for example 4.0x3.0, and everything else in your game (units movement, distance calculation, etc) must conform to that measurement you've set. That means a unit that moves at 4.0/sec will move across the screen in one second.


Also using this method, you will not have to take adjusting speed into account like alnite suggested which would normally be required. This is because you are always calculating for your native 1024x768 resolution that is being generated in the backbuffer. The display is just an appropriately scaled output along with which the movement, etc will automatically be scaled.

IDirect3DDevice9::StretchRect() method can be used to scale to both up-res and down-res. So you can stretch a 1024x768 screen to 640x480...


This would require me to render the scene on a 1024x768 texture/surface, and then scale it down to my 640x480 screen.
But, I can't do that. I can't make a render texture bigger than my screen size. I tried that.


g_engine->p_device->CreateTexture(1024,768
1,D3DUSAGE_RENDERTARGET,D3DFMT_R5G6B5,D3DPOOL_DEFAULT,&this->p_RenderTexture,NULL);

this->p_RenderTexture->GetSurfaceLevel(0,&this->p_RenderSurface);


When I render on it and scale it down, even though I put 1024x768, it still renders only 640x480 part of the scene.
D3DTexture cannot be scaled, only D3Dsurfaces can.

This topic is closed to new replies.

Advertisement