Windowed mode and fullscreen showing different parts of the screen

So I’m trying to get windowed mode and fullscreen mode to show the exact same image of the game I’m trying to make, but so far the windowed mode only shows the top left portion of the screen. How would I go about making it so what I see on the windowed version and the fullscreen version are the same, aside from the different sizes? Any advice on how to do this, links to other threads, etc would be appreciated!

What does your Contruct for Game class look like?

graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = “Content”;

Just what it came preloaded with

Ah - you can setup stuff for graphics like this:

graphics = new GraphicsDeviceManager(this) {
    PreferredBackBufferWidth = 1024, PreferredBackBufferHeight = 768,
    IsFullScreen = false 
};        

If you want pixel-perfect match (same aspect ratio) regardless of desktop resolution you can use a RenderTarget2D to draw on instead of regular back-buffer and then draw the result to the backbuffer like so (below is windowed but acts like full-screen mode) [this is also useful in preventing security software conflicts]:

public game1 {            
    int initial_screen_width  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
    int initial_screen_height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
    graphics = new GraphicsDeviceManager(this) {
        PreferredBackBufferWidth = initial_screen_width, PreferredBackBufferHeight = initial_screen_height,
        IsFullScreen = false,                            PreferredDepthStencilFormat = DepthFormat.None        
};            
Window.IsBorderless   = true;            
Content.RootDirectory = "Content";
}

And then in Initialize:

// RENDER TARGETS     
gpu = GraphicsDevice;
pp  = gpu.PresentationParameters;    
SurfaceFormat format = pp.BackBufferFormat;    
DepthFormat   depthFormat = pp.DepthStencilFormat;   
int multiSamps = pp.MultiSampleCount;              
targetBuffer  = new RenderTarget2D(gpu, 1024, 768, false, format, depthFormat, multiSamps, RenderTargetUsage.DiscardContents);

And then in Draw:

#region D R A W   T A R G E T   T O  B A C K B U F F E R
gpu.SetRenderTarget(targetBuffer); 
// DRAW STUFF HERE
//...
gpu.SetRenderTarget(null); // set target as backbuffer
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone);
spriteBatch.Draw(targetBuffer, desktopRect, screenRect, Color.White);
spriteBatch.End();
#endregion

So I started looking through your code, and p much just copying it, but then I came across an issue. I started deleting things so I could find the original problem to maybe screenshot it/explain it better or something, but when I tested it, it worked. I forgot to delete this stuff
int initial_screen_width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; int initial_screen_height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
So yeah, I didn’t need to use all of it, and it seems to work. Thanks!

1 Like