PDA

View Full Version : Plotting Slowly



zak
30-01-2009, 13:21
hello
i am trying to draw the sine function, but slowly pixel by pixel, as if it is animated.
it seems to me there is a heavy task on the computer, since if we just move the window by the mouse the program will hang.
the plot will repeat again and again due to the WHILE TBGL_IsWindow(hWnd), but i want the plot to stop after the first plot finished, and keeping the picture on the screen.
any suggestions ?

ErosOlmi
30-01-2009, 13:43
Ciao zak.

To avoid hang, you just need to give some free time to the operating system adding a DOEVENTS command just before NEXT. So something like

FOR ...
...
DOEVENTS
NEXT

Without a DOEVENTS you scripts will use all the processor time not leaving other applications (operating system included) enough time slices to do their job. You have always to try to write code in "geneorus" way and not in "egoistic" way that is try to get the minimum CPU time you need and leave the rest to other process. DOEVENTS does this job. Also SLEEP does this job.

Anyhow, to achieve better results, the ideal solution could be to use TBGL in CANVAS mode building a dialog with the UI module and than using dialog timers fired at exact timing frames, the one you need.
Maybe Petr can give more info about that. Also there are examples in \thinBasic\samplescripts\UI\Callbacks\ directory showing this.

Ciao
Eros

Petr Schreiber
30-01-2009, 13:57
Hi Zak,

there are few problems in your code, like using TBGL_PointSize between TBGL_BeginPoly / TBGL_EndPoly, and little redundant swapping of buffers.

I will prepare version for you during today, it will use timers (for low CPU usage and good redraw ).

Thanks for asking about this problem.

Petr Schreiber
30-01-2009, 14:25
Here goes one of possible solutions :)

It should be pixel perfect even when resizing, and doing the animatin just once.

Key features:
- use of TBGL canvas
- use of timers to pump graphics
- use of TBGL_RenderMatrix2D to setup custom resolution

zak
30-01-2009, 15:16
(very ^ 1000000) beautiful , thank you very much