Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've got a 2D game that I'm working on that is in a single aspect ratio. When I switch it to fullscreen mode on my widescreen monitor it stretches. I tried using two viewports to give a black background to where the game shouldn't stretch to, but that left the game in the same size as before. I couldn't get it to fill the viewport that was supposed to hold the whole game.

How can I get it to go fullscreen without stretching and without me needing to modify every position and draw statement in the game?

share|improve this question

2 Answers 2

You can just set your ProjectionMatrix like so:

ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4,
                                                        (float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height,
                                                        1.0f,
                                                        3000.0f );

This will set your aspect ratio correctly, in whatever screen you're using.

share|improve this answer
    
projection matrix? Isn't that just if you're using cameras? My game is only in 2D so I'm not using a camera. –  user4873 Jan 25 '11 at 2:29
    
this answer was really helpful! thanks. –  townsean Aug 30 '11 at 15:08

From: http://forums.create.msdn.com/forums/p/58545/358858.aspx (emphasis mine)

There is a very simple answer to your question: your monitor is a widescreen monitor, if you set a non-widescreen resolution to it, it will have to stretch the output to give you an image. Some graphics adapters and some screens provide a '4:3 in wide' mode which destretches for you.

However if you want your game to always look right and not be stretched you have todo the following:

  • Render to a rendertarget instead of to the screen directly
  • Get the texture from the render target
  • Clear the screen to black
  • Start a spritebatch and render your texture at the correct aspectratio on screen scale it by using an overload that uses the targetRectangle, this way you have automatic black borders either above or on the sides.

This should be be realy easy to implement :)

share|improve this answer
1  
The problem is explained above (Monitors will generally stretch out an image to make it fit in full screen). I however think the easiest solution is to just change your rendering resolution with the adapter to a support full screen resolution. I would imagine that XNA still has the render mode enumerable that you can get that information from. –  James Jan 25 '11 at 17:22
    
Exactly, there isn't an automatic way to do this for 2D -- you need to render on something besides the screen, then render that to the screen. –  Nate Jan 27 '11 at 22:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.