XNA to render 3D video (fixed FPS!)

我们两清 提交于 2019-12-08 06:02:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/3616232/xna-to-render-3d-video-fixed-fps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!