XNA for rendering 3D video (fixed FPS!)

I need to develop an application in which the last step is to export the video (or one frame) of the 3D animation created by my software to calculate the user input parameters.

I want to use XNA for this as well. I need the software to be able to export FIXED FPS video (or all individual frames of video separately). This is not a LIVE FPS question. I do not need to view frames with fixed fps on the screen. Since animation can be very complex, I can accept if the software takes 1 minute for each frame.

The important thing is that I see the frame during its rendering and does not skip any frame. eg. if the video lasts 1 minute, it should export 24 frames at 24 frames per second, also if it takes 20 seconds for each frame. After rendering the first frame (after 20 seconds), it should not display the frame in 21 seconds. it should display a frame [2/24 of the first minute]

How can i get this?

Thanks!

+1
source share
1 answer

Here is the method for XNA 4.0 described in the code for your Game class (because it is 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 compilation or testing - so there may be a small error or two.

+1
source

Source: https://habr.com/ru/post/1346441/


All Articles