[fpc-pascal] Fastest way of drawing 2D graphs

Marco van de Voort marcov at stack.nl
Fri Sep 12 13:00:21 CEST 2014

In our previous episode, Hunter1972 said:
> I am new in FPC and want to understand the correct(fastest) methods when drawing 2D graphics.
> The task is simple but extensive: to draw about 200 polylines with 50000-200000 points in each.
> I have made a test code in OnPaint event:

OpenGL is an option here. Basically you upload a bunch of vertices and draw
them. I do so with the overlay of vision algorithms over the camera image.

Still, even then, the number of points is excessive. Specially when it also
must work on integrated graphics. Uploading it to the graphic card of the
points alone is costly. 

Also programmingwise, this is the most effort, and thus not for the faint of
> It works fine (png is attached).
> Then I'd like to add some actions to the graphics:
> 1)Scaling around some point (by mouse wheel), actually magnifying
> 2)Moving this scaled point quickly to another part of graphics( using scroll bars?)

This is cheap in opengl, and was my main motivation to start that
non-trivial project. A repaint of already uploaded data is sub-ms and
lightning fast.

Only uploading of data takes time (burst rates on external GPU are in the 1-2ms/MB magnitude,
less in the integrated case. Basically you can upload a few MB till it

> The main question is:
> 1)How to correctly organize this drawing that it'll take a lot of time only once before the first display?
> Later actions (scaling and moving) should be as fast as possible provided that points array (Times and FileDetections)
> are not changed.

I assume your polylines are basically an array of X,Y coordinates in single
precision + color information? If you supply examples of those, I'll see if
I can hack something together. (binary only, since it is a work codebase,
more to get you an idea of how workable it would be)

What I currently don't have is autoscale, but that can be easily hacked in
by calculating min and max of x and y, and dividing all coordinates by

My guess I can get it to show sub 100ms, with changing viewport (scaling
etc) sub ms.

More information about the fpc-pascal mailing list