Jump to content
  • Advertisement
Sign in to follow this  
Maxamor

[XNA] Fullscreen & StretchRectangle

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

Hello all. I have put myself in an interesting predicament. The game I have been working on is running fine in windowed mode. The resolution in windowed mode is 320x240--which happens to be just right for my game. When I swtch to fullscreen, the viewport becomes 640x480 and there doesn't seem to be any way to control this. The result is that my 320x240 backbuffer is copied to the top-left corner of the screen, leaving a rather large blank area around it. The simplest solution, in my opinion, would be to draw everything as I would if it were in windowed mode and then right before the backbuffer gets flipped to the front, stretch my 320x240 image to the size of the viewport. This way, no matter what resolution a player is running on in fullscreen, the graphics will be consistent. That's great. But how do I do this? I was directed to use the GraphicsDevice.StretchRectangle method. This seems correct to me. However, I am encountering issues when implementing this method call. Very often I get InvalidCallException (usually because I'm trying to modify a buffer that I'm not allowed to). Has anyone had a problem like this? How did you fix it? Has anyone used StretchRectangle? How can I get the results back to the frontbuffer? Thanks in advance, I hope my problem was presented clearly.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure how different it would be in XNA rather than vanilla Direct3D, but I'd prefer to use the view/projection matrices to adjust everything for me, so that I have a fixed coordinate system that I can always use (320x240 in your case), and only a few lines need to be changed in order to fill different resolutions. Depending on your stretching/filtering needs, this might satisfy you quite well. It also gives you the flexibility to shift your 320x240 into the center of the screen with black on all sides if you wish, to maintain pixel-perfect accuracy.

Share this post


Link to post
Share on other sites
This sounds like a good idea and it was also something I was thinking about. The thing I really didn't want to do was scale each thing individually because it would be a huge waste.

For this game, I don't plan on having any of the sprites or graphics scale in any way whatsoever, so one master matrix would be ideal.

Share this post


Link to post
Share on other sites
I have been reviewing the camera "tutorials" that come with XNA GS Express, but I noted that they say "it is assumed you are using a CompiledEffect" or something like that. I didn't plan on using any effect files, but it seems to me that the camera can only be modified by using an Effect. Is this accurate?

If adjusting the view/projection matrix, I would only have to set the x "scale" and y "scale" to some value (in this particular instance--2.0f) depending on resolution and I could achieve my goal, correct?

EDIT: I have fixed this issue, although it is probably in an inefficient way--it works and I like it.

When the device is created, I create an additional Texture2D Render Target that is the dimensions of the viewport.

After all of my rendering at 320x240 is done, I use the StretchRectangle() method as described eralier to draw my backbuffer to this alternate Render Targate at the correct size.

Following that, I use the SpriteBatch.Draw() method to draw the screen like a sprite at the size of the viewport.

[Edited by - Maxamor on October 19, 2006 1:50:24 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!