How to implement high-speed animation?

I am trying to write an application (winforms) that can demonstrate how two oscillating colors will result in a third color. To do this, I need to be able to switch between the two colors very quickly (at> 50 frames per second). I really hope to do this in managed code.

Now I am drawing two small rectangular bitmaps with solid colors on top of each other. Using GDI + DrawImage with two in-memory bitmaps in double buffer control mode does not cut it and results in flickering / tearing at high speeds. A timer connected to the slider starts the toggle.

  • Is this a sane approach?
  • Will GDI and BitBLT Be Better?
  • Does WPF perform better?
  • What about DirectX or other technology?

I'd really appreciate your feedback, TIA!

+2


source to share


3 answers


I've never been able to do high-speed graphics with GDI, so I used DirectX, but MS dropped support for Managed DirectX, so you might need to do it in unmanaged C ++.

Just write your controller in C # and then get a very thin layer of managed C ++ that just calls the unmanaged C ++ DirectX DLL.



You will need to take exclusive control of the computer so that no other application can actually use the processor, otherwise you will find that the frame rate may drop, or at least not be very consistent.

If you are using an older version of DirectX such as DirectX 9.0c which may still support .NET and I have used that to get the frame rate for a music program at around 70fps.

+2


source


Flicker should be avoided with a double-buffered method (and by that, I don't mean just setting the DoubleBuffered property to True - ironically, it won't affect flicker).

Destruction can be handled through DirectX, but only if you sync your frame rate to the monitor's refresh rate. This may not be possible, especially if you need to achieve a certain frame rate (and it won't be your monitor refresh rate).



I don't think WPF gets around the main rip problem (but I could be wrong).

+1


source


This will work with GDI, but you won't be able to control the flicker, so that's not a question. A straight X can have a lot of extra fluff just to show two non-flickering images. Perhaps SDL will work well enough? It's cross platform and you can literally code this effect in less than 30 lines of code.

http://cs-sdl.sourceforge.net/index.php/SimpleExample

+1


source







All Articles