XNA Creators Club Online
Page 1 of 1 (19 items)
Sort Posts: Previous Next

Fullscreen mode

Last post 7/19/2009 5:20 PM by Sam DJMAX Eddy. 18 replies.
  • 7/19/2009 3:49 AM

    Fullscreen mode

    Hello again all! Ive searched MSDN and many forums but just can't quite crack this one....

    Problem - I need my game to be displayed in a full screen mode of (320x200) [the little overlay box] and its displaying much wider and taller than that. help?

    What ive tried - changing the preferred backbuffer info, changing my PCs resolution, different methods of toggling to full screen mode in XNA

    attached is a screen shot of whats happening (its Clyde! :] ) i need it to ONLY be the box, not much of a puzzle game if you can see more of the lvl than ur supposed to.

    Thnx a ton guys

    -Sam


    Note: also, my resolution is 1280x800 and the screenshot is smaller than that so it is altering it somehow and the only commands i have in there right now are (graphics.toggleFullScreen();)

    -DJMAX
  • 7/19/2009 4:05 AM In reply to

    Re: Fullscreen mode

    Your system may not support 320x200, or anything less than 640x480.

    What you can do here is render your game to a 320x200 render target, and then draw that over the screen, stretching it. Or switch your rendering code to use resolution independent coordinates.
    return;
  • 7/19/2009 4:13 AM In reply to

    Re: Fullscreen mode

    thats exactly it! :D (my computers monitor has a lowest resolution setting of 800x600, THUS the game screen with a height of 600pxl)

    so... this streching the game to 800x600 business.... how might i go about doing that?? (without it toying with my x, y coordinates of all my sprites and stuff)

    thnx a ton

    -Sam
    -DJMAX
  • 7/19/2009 4:34 AM In reply to

    Re: Fullscreen mode

    Use a render target to render your game screen, then draw that to the screensize. Nothing will change here, you are rendering the same as now, but everything is going on a 320x200 surface instead of direct to the back buffer. You can then take the output, and use a fullscreen SpriteBatch.Draw() call.

    http://blogs.msdn.com/shawnhar/archive/2007/02/04/xna-rendertarget-semantics.aspx

    Or

    You can split the screen up using resolution independent coordinates. Meaning the screen goes from 0.0f-1.0f, regardless of how many pixels there are, and you just draw with fractional floating point coordinates.

    The end result should look the same, considering the graphics you have set up.
    return;
  • 7/19/2009 4:38 AM In reply to

    Re: Fullscreen mode

    gonna have to do some research on the render target stuff but i'll give it a shot! :D

    thnx a ton!

    -Sam
    -DJMAX
  • 7/19/2009 5:31 AM In reply to

    Re: Fullscreen mode

    ok... now im having this problem....

    after creating the RenderTarget2D and compiling i get this error.....

    on this line....

    RenderTarget2D renderTarget = new RenderTarget2D(graphics.GraphicsDevice, 800, 600, 1, SurfaceFormat.Color);

    ... it says "out of memory"


    help?

    thnx a ton

    -Sam
    -DJMAX
  • 7/19/2009 5:39 AM In reply to

    Re: Fullscreen mode

    The target should be 320x200, not 800x600.
    return;
  • 7/19/2009 5:52 AM In reply to

    Re: Fullscreen mode

    ok... well that fixed the error, but now its just a blank blue-ish-green screen.... but i think i know the problem.

    thnx a ton!

    -Sam
    -DJMAX
  • 7/19/2009 5:55 AM In reply to

    Re: Fullscreen mode

    Make sure to follow that link I posted, and read the later follow up post about how render targets are handled post 2.0.

    The basic flow here is that you are rendering to the 320x200 target as is it was the screen. All your render calls get routed there. When you are done, you have to switch your rendering back to the screen/backbuffer, and then draw a fullscreen sprite using your RenderTarget's texture as the data.
    return;
  • 7/19/2009 6:07 AM In reply to

    Re: Fullscreen mode

    followed the link and got most of it working, only prob is that for some reason my XNA (3.1) does not recognize the "device(for me its graphics.GraphicsDevice).ResolveRenderTarget" so all i get is a blank blue screen. :(

    the only "resolve" anything on the list is the "resolveBackBuffer" and when i tried that it just said that i cant because i have a renderTarget active.

    -Sam
    -DJMAX
  • 7/19/2009 6:13 AM In reply to

    Re: Fullscreen mode

    also, for another thing.... it stays on that blank blue-ish screen for a while than still does the "out of memory" thing. :(

    here is code in case it help....

    protected override void Draw(GameTime gameTime)
            {

                GraphicsDevice.Clear(Color.Black);
                // TODO: Add your drawing code here

                RenderTarget2D renderTarget = new RenderTarget2D(graphics.GraphicsDevice, 320, 200, 1, SurfaceFormat.Color);
                graphics.GraphicsDevice.SetRenderTarget(0, renderTarget);


                spriteBatch.Begin();

                spriteBatch.Draw(bg, new Rectangle(8, 8, bg.Width * screenMulti, bg.Height * screenMulti), Color.White);

                //draws the lvl blocks
                for (int height = 0; height < castleHeight; height++)
                {
                    for (int width = 0; width < castleWidth; width++)
                    {
                        spriteBatch.Draw(bricks, new Rectangle(lvl[width, height].X, lvl[width, height].Y, lvl[width, height].Width * screenMulti, lvl[width, height].Height * screenMulti), blocks[width, height], Color.White);
                    }
                }

                if (direction == "left")
                    spriteBatch.Draw(clyde, new Rectangle(clydeDraw.X, clydeDraw.Y, clydeDraw.Width * screenMulti, clydeDraw.Height * screenMulti), clydeSprite, Color.White);
                else if (direction == "right")
                    spriteBatch.Draw(clyde, new Rectangle(clydeDraw.X, clydeDraw.Y, clydeDraw.Width * screenMulti, clydeDraw.Height * screenMulti), clydeSprite, Color.White, 0f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0f);


                spriteBatch.Draw(overlay, new Rectangle(0, 0, 320 * screenMulti, 200 * screenMulti), Color.White);

                spriteBatch.End();

                graphics.GraphicsDevice.SetRenderTarget(0, null);

                base.Draw(gameTime);
            }
    -DJMAX
  • 7/19/2009 6:32 AM In reply to

    Re: Fullscreen mode

    http://blogs.msdn.com/shawnhar/archive/2007/11/21/rendertarget-changes-in-xna-game-studio-2-0.aspx

    As for out of memory. No wonder! Why are you allocating a new rendertarget every frame?

    Once you finish drawing your screen to the render target, you still have to set the rendering back to your screen so that you can draw the render target to the back buffer! Otherwise, you are just rendering your screen to an offscreen buffer.
    return;
  • 7/19/2009 6:44 AM In reply to

    Re: Fullscreen mode

    i know its asking a lot... but... would you please just throw me an example of code, cuz the links just confuse me more :/ sry... :(

    -Sam
    -DJMAX
  • 7/19/2009 7:03 AM In reply to

    Re: Fullscreen mode

    Sure. Just wait a little bit.
    return;
  • 7/19/2009 7:44 AM In reply to

    Re: Fullscreen mode

    Sam DJMAX Eddy:
    i know its asking a lot... but... would you please just throw me an example of code, cuz the links just confuse me more :/ sry... :(

    -Sam


    I just wrote a long post and the forum ate it when I hit post. I just got taken right back to this screen. What the heck?

    Okay, here you go.

    The simplest sample I can cook up.

    http://pastebin.com/f1e550270

    This is my first time ever using a render target, so it may not be the most optimal sample, but it works.

    How it works is very simple.

    I initialize a new 320x200 RenderTarget2D object ONCE.

    In my draw method, I tell XNA that I will be rendering on this target.

    I draw everything as normal, as if I was rendering to a 320x200 screen, but everything is being rendered onto a texture.

    I tell XNA that I will be rendering on the backbuffer again by setting a null render target.

    I use spritebatch to draw my target's texture to the screen. I use a new rectangle here so that it will always have the proper screen coordinates incase you get a different backbuffer through full screen toggling. You can handle this better by storing the coords in your own rectangle variable, and updating it should the screensize change.

    In the future, you should design around at least 640x480. I don't even think you can set 320x200 in Vista at all, on any device.
    return;
  • 7/19/2009 4:05 PM In reply to

    Re: Fullscreen mode

    Perfect! Thank you so much for your time and efforts! Everything is working now! :D

    -Sam
    -DJMAX
  • 7/19/2009 4:33 PM In reply to

    Re: Fullscreen mode

    ok, so... its doing exactly what i want now thanks to all your help. however, i am curious, is there a way i can make it strech the sprites without making them blurry? (its set to strech screen to 1280x800 which is just a perfect 320x200 *4 so they shouldn't be blurry because ratio is exact same.

    Thanks a ton

    -Sam


    -DJMAX
  • 7/19/2009 5:04 PM In reply to

    Re: Fullscreen mode

    You have to point sample the texture. Right now you are doing Linear sampling when you magnify it.

    Change the last part to this:

    //draw your rendered texture (target) to the backbuffer
                spriteBatch.Begin(SpriteBlendMode.None,SpriteSortMode.Immediate,SaveStateMode.None);

                graphics.GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
                graphics.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;

                spriteBatch.Draw(Target.GetTexture(),
                    new Rectangle(0,
                        0,
                        graphics.GraphicsDevice.Viewport.Width,
                        graphics.GraphicsDevice.Viewport.Height),
                    Color.White);
                
                spriteBatch.End();
    return;
  • 7/19/2009 5:20 PM In reply to

    Re: Fullscreen mode

    Flawless. Absolutely flawless! :D thank you so much!

    :] :D :] :D :] :D :] :D :] :D :] :D :] :D :] :D :] :D :] :D :] :D

    -Sam
    -DJMAX
Page 1 of 1 (19 items) Previous Next