Jump to content
  • Advertisement
Sign in to follow this  
samson77

2d Adventure change of resolution

This topic is 3659 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

Hi there, I've been programming on a 2d adventure game using DirectX and C++ for a while now. I've never thought about that people who might want to play my game might actually have to use a different solution than me (1680x1050) since at the moment this is not so common. My questions is how do I go about letting the user select a different resolution? When my app is started I call CreateWindowEx with the width and height of 1680x1050 and then initialize DirectX with the same resolution. What would I need to do to let the user select a different resolution? Do I have to uninitialize DirectX, destroy the window I've created with CreateWindowEx and then call CreateWindowEx with the new parameters and then initialize DirectX again? Or is there a better solution? The second question is: I have to triangles that span the whole width and height of the resolution and render at texture to them (as the background). This would scale to any resolution, I guess. But what do I do about my sprites? Do I just scale them up/down as well according to the current resolution? I hope someone can help me out of this dilemma. Cheers, Sam

Share this post


Link to post
Share on other sites
Advertisement
If you're running fullscreen, you don't need to create the window at the appropriate resolution - you can create it at pretty much any size and DirectX will take care of claiming the whole screen when you call CreateDevice.

As far as changing resolutions at runtime goes, the correct method to do this is to call IDirect3DDevice9::Reset() with a new set of PRESENT_PARAMETERS that describes the screen mode you want to switch to.

And yes, you will just scale your sprites up and down according to the resolution.

Share this post


Link to post
Share on other sites
I use a .ini file with the following entries

widescreeen = 0/1
width = 640/800/1024/1280/any supported res
fullscreen = 0/1

and read from it at startup to decide what settings to use - if the ini doesnt contain the right info, use a safe setting - this avoids any nastiness involving closing windows etc. but means that the player must manually edit the.ini (at the moment), although in later versions I plan to put all game settings in there, and edit the ini file when the player changes options - this would still require a restart to change core settings, but last time I looked this was pretty common for AAA games as well, a restart of the game for a resolution change is pretty standard.

i then use scaling for my sprites, yes, it works great. You need to do all the setup in a standard resolution, I use 1024*600 since my game is intended to be widescreen and I ned to run windowed for debugging. Here is the code for my sprite drawing function:


D3DXVECTOR2 scaledScale(m_scale.x * m_scrnScale.x, m_scale.y * m_scrnScale.y);
D3DXMATRIX mat;

if (m_bEnableAutoScale)
{
D3DXVECTOR2 comp;
if (GDevice()->Widescreen())
comp = D3DXVECTOR2(0.0f, (float)-(192.0f*(GDevice()->Width()/1024.0)));
else
comp = D3DXVECTOR2(0.0f, (float)-(128.0/1024.0)*GDevice()->Width());

D3DXVECTOR2 scaledPos(m_pos.x * m_scrnScale.x + comp.x, m_pos.y * m_scrnScale.y + comp.y);
// out, scaling centre, scaling rotation, scaling, rotation centre,
// rotation, translation
D3DXMatrixTransformation2D(&mat, NULL , 0.0f, &scaledScale, &m_centre, m_fRot, &scaledPos);
}

else
{
// out, scaling centre, scaling rotation, scaling, rotation centre,
// rotation, translation
D3DXMatrixTransformation2D(&mat, NULL , 0.0f, &scaledScale, &m_centre, m_fRot, &m_pos);
}


GDevice()->GetSpriteDevice()->SetTransform(&mat);

HRESULT result;
result = GDevice()->GetSpriteDevice()->Draw(m_pTex, NULL, NULL, NULL, m_colShift);




if you have sprites whose positions are unlikely to change from frame to frame it would be more efficient to store your position matrix and reuse it instead of rebuilding every frame.

EDIT: extra note - if you want to draw a (custom) cursor, then you will probably want to include a flag, as I did, to disable the position scaling, but maintain the size scaling. Otherwise, on entering the app the cursor will jump to a scaled position and you may find that you cannot move your mouse to all of your window.

Share this post


Link to post
Share on other sites
Thanks, guys, I really appreciate your quick answers.
Just one more question about sprite scaling:
I am not using any transform matrices or anything like that since I set the custom vertex to D3DFVF_XYZRHW; so everything is transformed already. Do you think this will become an issue regarding sprite scaling or do I just change the scaling parameters in the sprite's draw function?
Cheers,
Sam

Share this post


Link to post
Share on other sites
In that case you will need to work out the maths required to transform your screen coordinates to different screen coordinates, but it should be a similar idea to the snippet I posted, only applying the factors directly to your coordinates before drawing. Trial and error is your friend - set up your ability to change the resolution the game runs at, and then fix the positioning and scaling of the sprites so you can see if what you have done looks right :P

Mathmo

EDIT: or, if all your sprite stuff is nicely encapsulated, which I suppose it must be, you could probably switch the vertex format pretty easily. Depends which is less work, as both would seem to be adequate solutions.

Share this post


Link to post
Share on other sites
What do you think is the better solution:
Doing the transformation using matrices myself as you do (Mathmo) or having everything transformed already using D3DFVF_XYZRHW for the vertex buffer?
Cheers,
Sam

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!