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

Rendering every frame

Last post 09-10-2007 5:49 PM by drew65949. 6 replies.
  • 09-05-2007 8:31 AM

    Rendering every frame

    Hello public,

    I would really like to know how to render each frame before moving on.  As a reference to what I want to happen, the FPS would remain the same throught the program.  My goal is to capture each frame in a bitmap or whatever and then I can use XNA as an easy place to make cutscenes.  But the problem is, my graphics card isn't high end enough to be able to draw every single frame.  So how do I stop execution until it has rendered, then take a screenshot.

    ============================== Don't sweat the petty stuff and don't pet the sweaty stuff. ==============================
  • 09-05-2007 10:46 AM In reply to

    Re: Rendering every frame

    Just add the screen capture code into the end of your Draw() method. Though there area lot of frames drawn they are not drawn in a background thread or anything so wherever you put the code it will stop the program.

    Since you know your FPS speed is less than ideal make sure you don't use the timer for your animation but instead code a constant 30fps (or whatever you expect your final movie to be) as the time delta between frames otherwise your animation will all look wrong.



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 09-07-2007 3:09 AM In reply to

    Re: Rendering every frame

    I don't know how use plan to use those bitmaps, but if you plan to use the cutscenes in the same engine you use to create them, you could do cutscenes a lot more resource saving way. You could just save the random seed(s) you use to initialize Random instances, and save the input commands you enter, and maby the GameTime - in you Update method. Using that information, you are able to "playback" the scene just like you played it. This requires some modifications to the engine, but could pay off. At least you don't have to add large video files to you game. And using playback, your cutscenes look always as good  as the game itself. If you change some textures, the cutscene automatically uses those.

    And I personally hate cutscenes that "takes me off the game", that is that the cutscene is nothing like the game itself ;) They can ruin the mood!
  • 09-09-2007 9:45 PM In reply to

    Re: Rendering every frame

    With seperate cutscenes and rendering every frame, I could do much more detail at a faster speed than if I had the computer doing it in-program.
    ============================== Don't sweat the petty stuff and don't pet the sweaty stuff. ==============================
  • 09-09-2007 10:45 PM In reply to

    Re: Rendering every frame

    I got it figured out:

    It turns out that it was updating more than it was drawing, therefore it was translating objects and such much more than it should have per frame, so the playback was super fast.  But I figured it out.  Here's the code, feel free to use it for your needs.

    Record and Playback:

    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Storage;
    using System.Threading;

    namespace WAR
    {
    class VideoPlayback
    {
    string directory;
    int frame = 1;
    ContentManager manager;
    GraphicsDevice device;
    Texture2D playback;
    SpriteBatch playbackbatch;
    public VideoPlayback(string Directory, ContentManager Manager, GraphicsDevice Device)
    {
    directory = Directory;
    manager = Manager;
    device = Device;
    playbackbatch = new SpriteBatch(device);
    }
    public void Playback(int EndOfPlayback)
    {
    playback = manager.Load<Texture2D>("Content\\Video\\VideoPlaybackscreenCapture" + frame.ToString());
    if (frame < EndOfPlayback)
    frame++;
    else
    frame = 1;
    playbackbatch.Begin();
    playbackbatch.Draw(playback, Vector2.Zero, Color.White);
    playbackbatch.End();
    }
    public void Record()
    {
    using (Texture2D screenshot = new Texture2D(device,
    (int)device.Viewport.Width, (int)device.Viewport.Height,
    1, ResourceUsage.ResolveTarget,
    SurfaceFormat.Color, ResourceManagementMode.Manual))
    {
    device.ResolveBackBuffer(screenshot);
    screenshot.Save(directory + "screenCapture" + frame + ".png", ImageFileFormat.Png);
    }
    frame++;
    }
    }
    }

    Note: Recording is really slow.  To record: VideoPlayback.Record();  To playback: VideoPlayback.Playback(NumFrames);  Be aware - playback expects the files to be inside the "bin/x86/Debug/Content/Video" folder.  Sorry.  Still haven't worked out recording sound, so any help is accepted.

    Tracking draw/update whilst recording:

            protected override void Draw(GameTime gameTime)
    {
    hasBeenDrawn = true;

    ...

    protected override void Update(GameTime gameTime)
    {

      ...
    if (hasBeenDrawn)
    //do updatey stuff

    Glad I could give back to the community with this. 

    ============================== Don't sweat the petty stuff and don't pet the sweaty stuff. ==============================
  • 09-10-2007 3:03 PM In reply to

    Re: Rendering every frame

    f you want to keep Update from being called multiple times, you can just do:

    this.IsFixedTimeStep = false;

    in your Game init method.  with that set to false, XNA will just call update() once, and draw() once per frame, instead of trying to "catch up" by calling update() multiple times each (slow) frame.

    P.S. The actual property might be called something different, I wrote this from memory...
    Go Go Gadget XNA!
  • 09-10-2007 5:49 PM In reply to

    Re: Rendering every frame

    Thanks, that made my life a lot easier.  How'd you like the record/playback code?
    ============================== Don't sweat the petty stuff and don't pet the sweaty stuff. ==============================
Page 1 of 1 (7 items) Previous Next