
Creating Animation With Timer
Posted Sunday, 8 April, 2012 - 07:19 by siemonday inHi, I'm trying to draw some math graphics using opentk.
I create a double[] array to store the numbers,
and when the first graphic displays, the numbers in the double will be changed,
and then display the next frame.
As Application.Idle do not work for me , I tried to use System.Timer,but it tells me that I can not swap buffers ( I thought the context calculated stays in the timer's thread instead of the main thread so I can not swap them)
SO do anyone have some advice for me,how to create an animation?


Comments
Re: Creating Animation With Timer
I don't know if I understand you correctly, but I assume you want to realize animation like in cartoons - draw a new image every few milliseconds, is that right? If so, than this is not what you do in OpenGL. You usually use a double-buffered display which are swapped for drawing, so you do continuous drawing to the back buffer, not only on changes. I don't understand what you mean with the timer's thread - for standard OpenGL drawing, you do not need multithreading, as OpenGL does not support multithreading.
For timers you should take a look at the Stopwatch class, which is much more accurate for timing purposes, the System.Timer is useless for millisecond precision.
If I understood you correctly and you want to do this incremental animation, what you would do is:
- Start your stopwatch
- Enter the game loop (i.e. a while loop with update(), render(), swapbuffers())
- Clear the back buffer
- In each iteration, check the stopwatch time: if it's greater than some time period p1, draw object o1. If it's greater than time period p2, draw object o1 and o2 and so on.
This way, you redraw each object in each frame continuously, but with your time period conditions you specify what objects to draw (additionally) depending on the elapsed time.
Re: Creating Animation With Timer
Thank you mOfl !
I write update and render function, trying to re-draw the image.
Code below ( Click button1 to update the values,and click button2 to re-draw , but it do not display the new values when updated. )