Change aspect ratio

Apr 17, 2009 at 10:18 AM
Edited Apr 17, 2009 at 11:30 AM
Hello!
I'm quite new to programming with graphical frameworks, but it's neccassary for my diploma thesis (something with sound particles). I need some framework to do the job quick & dirty (or better: quick and clean), so I stumbled over Xen. It's a fine work, you don't have to mess around with all the details. Just do what I need.

And here's my question. I created a Xen window with a specific size, e.g. 800x600 pixels. But when I change to fullscreen and changing the resolution to 1440x900, the aspect ratio also changes from 4:3 to 16:10. Then all objects are warped, a circle becomes an egg-shaped something. How can I adjust the aspect ratio to the current window's resolution?

This code I got from the tutorials for initial changing of resolution:
protected override void SetupGraphicsDeviceManager(Microsoft.Xna.Framework.GraphicsDeviceManager graphics,
ref RenderTargetUsage presentation)
{
graphics.PreferredBackBufferWidth = InitialWidth;
graphics.PreferredBackBufferHeight = InitialHeight;
graphics.IsFullScreen = false;

this.graphics = graphics;
}
When I change the resolution at some point, using the stored graphics object, it becomes the described mess. I don't know where to setup the aspect ratio... the camera object doesn't seem to have a method for. Can someone help me? Thanks a lot. :) I'm really new to this stuff, maybe I don't see the obvious solution...
Coordinator
Apr 17, 2009 at 10:47 AM
Hi.
3D Cameras store a Projection object, which internally stores a nullable float for the desired Aspect ratio.
When set to null, which is the default, the aspect is computed by the size of the render target / screen.
Apr 17, 2009 at 11:29 AM
Edited Apr 17, 2009 at 11:30 AM
Thanks, I understood this. :) So I may either change the camera's aspect ratio, or change the size of the render target/screen.
The first solution works fine, but I'm interested in changing the screen's size. The DrawTargetScreen.Size property is readonly,
and reinitialising won't change its size, despite the new size of the graphics object... (ok, I'm seeing this too naive, but I'm still learning)
Coordinator
Apr 17, 2009 at 9:48 PM
Are you changing the resolution at runtime? I don't provide any tested way to do this (You'd need to store the GraphicsDeviceManager), but it should work...
Apr 17, 2009 at 10:05 PM
Ah, okay ... I thought there was a Xen-built-in possibility to do this, but it seems that it has to be the XNA way. *g*

Is it inconvenient to change the resolution? I tried some tutorials, played a bit and wanted to add a fullscreen toggle button (since there is a fullscreen toggle method). But ToggleFullscreen() only sets fullscreen with the same window resolution, which is quite senseless. It should switch to full display screen resolution (in my case 1440x900). Then the monitor doesn't need to interpolate.

So ... changing PreferredBackBuffer's size only resets the resolution, but I don't gain any additional screen space (a circle is just bigger displayed). Seems that I'd have to create a new DrawTargetScreen with a different size. Okay, doesn't matter at the moment. I was just curious about the inner workings.
Coordinator
Apr 19, 2009 at 4:15 AM
I leave most of the resolution / window setup stuff to existing XNA code, so there isn't a huge amount I can help you with.
I'd say for the majority of developers, having direct control over the resolution is preferred. You can get the screen resolution from the GraphicsAdapter. If you are drawing 2D elements (that are not normalised) they should draw at exact pixel sizes, otherwise all other drawing should appear the same screen size.