I know that when developing for Xbox in XNA, you basically just set the resolution to 1280×720 and the Xbox will just take care of things, but on PC I’m having some trouble getting the resolution handled correctly.
I would like it to be able to run at other resolutions, but I’m actually happy to make the game always widescreen and just be letterboxed on 4:3 screens. I can already handle scaling the game and it’s components but I cannot figure out how to get it letterboxed.
Obviously, this will not be necessary in windowed mode, but when running in fullscreen I just need to figure out how to get the game to only draw on part of the screen.
What’s the best way to do this?
You can set
GraphicsDevice.Viewportto the viewport that you want to use.The documentation has an example of how to do this (it does it for split-screen, but letter-boxing a single view is the same concept).
The GPU will handle clipping to this viewport for you.
Additionally your projection space will cover that viewport, so you don’t need to worry about doing any transformations (excepting that
SpriteBatchworks in a space that is the pixel-size of the viewport, not projection space, so you may have to do scaling if your viewport is larger or smaller than 1280×720; I describe more about the various spaces involved in this answer).To get black bars, simply do a
GraphicsDevice.Clear(Color.Black)with the viewport set to the full screen.