Viewport tweaks in XNA Game Studio 4.0

Viewport tweaks in XNA Game Studio 4.0

  • Comments 13

Game Studio 4.0 includes some tweaks to simplify common patterns when working with Viewport objects. We added two constructors:

    public Viewport(int x, int y, int width, int height);
    public Viewport(Rectangle bounds);

And we added a Bounds property to Viewport, Texture2D, and PresentationParameters:

    public Rectangle Viewport.Bounds { get; set; }
    public Rectangle Texture2D.Bounds { get; }
    public Rectangle PresentationParameters.Bounds { get; }

This makes it easier to do things like resetting the viewport to cover the entire surface of a rendertarget:

    GraphicsDevice.Viewport = new Viewport(renderTarget.Bounds);

or scaling a texture to fill the entire viewport:

    spriteBatch.Draw(cat, GraphicsDevice.Viewport.Bounds, Color.White);
  • Most of us have already created classes or methods to do this, but it’s really nice to have it already implemented.

  • the new spriteBatch.Draw(cat, GraphicsDevice.Viewport.Bounds, Color.White);

    is really very handy.

    Thanks posting

  • Ah finally, previously you'd have to write an extension method for this.

  • More changes that I can get behind!

    However, I would really like a SpriteBatch.DrawCat method. It would greatly reduce the amount of code I need to write just to draw a glorious cat.

  • > However, I would really like a SpriteBatch.DrawCat method.

    I've been arguing for some time that if you create a 256x256 Texture2D, but never call SetData on it, we should initialize this to the classic image of my cat.

    That's not technically even a breaking API change, because we never explicitly specified what the contents of an uninitialized texture are! A photo of a cat strikes me as a valid implementation of "undefined" :-)

    I have yet to convince the powers that be that this would be worth the extra 32k of framework assembly size, though :-)

  • The only solution for that is, of course, to make a procedural cat-drawing function. Totally worth the time it would take if you ask me!

  • > The only solution for that is, of course, to make a procedural cat-drawing function.

    Or maybe use web services to pull down a random lolcat?

  • Please put in viewport a swapbuffer like this

    allso presented on the xbox360

    recording of command buffers and viewports and playback function ,,

    so we can record a frame or to and play the frame back with only the visible objects or if objects that are change are updated to the new viewport

  • Michael: I don't understand what command buffer playback has to do with viewports? These seem like entirely unrelated features to me?

    If you have feature requests for future versions, the Connect website is the best place to suggest them.

  • command buffer ,

    sorry mistake,

    but still a swapbuffer as viewport

    render one frame to the fist viewport , and the second frame to the next viewport

    playback the fist viewport

    wicth meen we have to save all our rendertarget in a special place in the memory

    so that our rendertarget dont get lost

  • sorry shawn

    more of a memory that are dicated to hold all the rendertarget thrue our render pipeline

    more of a lock memory , so we can acess these rendertarget verry fast

    you see not all rendertarget need to be update evry frame

    in the net compact fromework as special 64mb memory chunck for that,

    so when we render one of the rendertarget it is copyed to the special ram on xbox360 , and when rendering is done ,it well been copy back to the same location in the 64mb chunk as before

    that way we can control the rendertarget/texture , faster

  • Michael:

    It would be great if you could try to keep these comments at least somewhat related to the topic of the blog article! It is natural that conversations tend to wander around a little, but blog comments aren't really the best place to bring up entirely new, unrelated subjects!

    If you have specific feature suggestions you would like to make to the XNA team, the Connect website is the best place for that.

    If you want to start a conversation about rendertargets, I would recommend the creators.xna.com forums.

  • Really liking the sound of all these changes. Just eager to get my hands on the real deal now...

Page 1 of 1 (13 items)
Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post