views:

56

answers:

1

Hi, i have to develop an application in wich the final step is to export a video (or a single frame) of a 3D animation generated by my software calculating the user input parameters.

I want to use XNA and for this. i need that the software can export FIXED FPS video (or also all single frames of the video separately). It's not a matter the LIVE FPS. I don't need to view on the screen the frames at a fixed fps. As the animation could be very complex, i could accept if the software take 1 minute for each frame.

The important is that i can see the frame while it render and that is not skipped any frame. eg. if the video is 1 minute long, it have to export 24 frames at 24fps also if it will take 20secs to render each frame. After rendered the first frame (so after 20sec) it haven't to render the frame at 21sec. it have to render the frame [2/24 of the first minute]

How can i obtain this?

Thanks!

A: 

Here is the method for doing this for XNA 4.0, described in code for your Game class (because it's easy for me):

protected override void Update(GameTime gameTime)
{
    // Do Nothing!
}

void RealUpdate()
{
    const float deltaTime = 1f/60f; // Fixed 60 FPS     
    // Update your scene here
}

RenderTarget2D screenshot;

protected override void LoadContent()
{
    screenshot = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, null);
}

protected override void UnloadContent()
{
    screenshot.Dispose();
}

int i = 0;

protected override void Draw(GameTime)
{
    RealUpdate(); // Do the update once before drawing each frame.

    GraphicsDevice.SetRenderTarget(screenshot); // rendering to the render target
    //
    // Render your scene here
    //
    GraphicsDevice.SetRenderTarget(null); // finished with render target

    using(FileStream fs = new FileStream(@"screenshot"+(i++)+@".png", FileMode.OpenOrCreate)
    {
        screenshot.SaveAsPng(fs, width, height); // save render target to disk
    }

    // Optionally you could render your render target to the screen as well so you can see the result!

    if(done)
        Exit();
}

Note: I wrote this without compiling or testing - so there might be a minor error or two.

Andrew Russell
Thanks for the answer! i will try!How do you suggest to track the time (current frame to update) in the RealUpdate() function?Should i implement some kind of integer counter and increment it for each RealUpdate? Or i should track anyway the time trough the XNA GameTime object?
Alex
You can do whatever suits your animation. You could store the number of seconds or frames since the start of your animation. Or you could store the position of everything and update it by a constant amount each frame (as you would in a real game). Don't create `GameTime` objects (normally you just read them - but in your case you are deliberately ignoring them). Store time as `float` or `double` (to store a number of seconds) or `TimeSpan`.
Andrew Russell