Drawing lines

44 views
Skip to first unread message

holm.h...@gmail.com

unread,
Oct 9, 2017, 3:25:33 PM10/9/17
to fltk.general

Hello,

Calling for ideas : Lines drawn to illustrate wind on https://www.windy.com/ seems to illustrate
the flowfield very well.

Any idea how to reproduce such an effect in fltk ?

Seems like the lines is transparent. Would it be an idea to have a bunch of one-pixel-size images with different transparency and to draw these instead of the line ?? would be slow  solution ?

Alternative/better ideas ?

Best regards
Håvard

Ian MacArthur

unread,
Oct 9, 2017, 5:08:22 PM10/9/17
to fltkg...@googlegroups.com
Looks like a natural job for OpenGL, TBH. Then you can get the hardware to do transparency and anti-aliasing and so forth for you...

Shouldn’t be too tricky now. The older GL API’s didn’t make it all that easy to set up an anti-aliased drawing context, but ISTR that Manolo did some work to make it easier to use fltk with Glew to get access to more sophisticated API’s, so probably not as bad now.





Greg Ercolano

unread,
Oct 9, 2017, 5:20:02 PM10/9/17
to fltkg...@googlegroups.com, holm.h...@gmail.com
On 10/09/17 12:25, holm.h...@gmail.com wrote:
>
> Hello,
>
> Calling for ideas : Lines drawn to illustrate wind on https://www.windy.com/ seems to illustrate
> the flowfield very well.
>
> Any idea how to reproduce such an effect in fltk ?

Several ideas come to mind:

a) If they're not transparent (and just have a fading trail of color),
then you can probably just use fl_point() or small fl_rectf()'s in a grayscale,
along with an Fl_Double_Window.

b) Or, you could try to render the "wind" directly into an rgba image, where the image
is cleared to 0,0,0,0, and then draw the wind lines over the map in white, and just
trail off the opacity channel, e.g. rgba=255,255,255,n, where n varies from 255 to 0
to implement the "fade".

c) Or, you could use opengl (which is probably what they're doing, webgl in their case)
and do fully transparent drawing.

The benefit of techniques (a) and (b) are to /avoid/ opengl, which can sometimes
be picky/weird, or not well supported on some graphics hardware.

Opengl technique (c) should be easier code wise, letting opengl give you access
to opacity rendering (not available with option (a)), and without having to make
your own line renderer code (option (b)), though I imagine that's trivial since
you probably need to render the 'trails' of wind as individual pixels or small boxes.


> Seems like the lines is transparent. Would it be an idea to have a bunch of one-pixel-size images with different transparency and to draw these instead of the line ?? would be slow solution ?

That's perhaps another idea, though might be a bit of overhead to have to redraw
an image all over. But it might be quick enough not to matter.. not sure!
I think option (b) might be better; you allocate an entire alpha image over the map,
and just set the pixels you want in RGBA, and then render that entire image over the
map or whatever the fixed background is.

Greg Ercolano

unread,
Oct 9, 2017, 5:23:56 PM10/9/17
to fltkg...@googlegroups.com, Ian MacArthur
On 10/09/17 14:08, Ian MacArthur wrote:
> Looks like a natural job for OpenGL, TBH. Then you can get the hardware to do
> transparency and anti-aliasing and so forth for you...

Agreed, though I've found some users have trouble with opengl, due
to weird driver issues.

> The older GL API’s didn’t make it all that easy to set up an
> anti-aliased drawing context

Hmm, I don't remember it being hard; I think it was just a single
init command to indicate alpha rendering, and then you could draw
pixels with gl_point() using rgba values.

I think it'd be easy, old or new opengl API, to use glDrawPixels()
to draw the map, and then gl_point() to draw the trails using RGBA,
where RGB=1.0 each, and A varies to do the 'fade'..

Ian MacArthur

unread,
Oct 9, 2017, 5:29:43 PM10/9/17
to fltkg...@googlegroups.com
Hi Greg,

It wasn’t transparency, so much anyway, that I struggled with, it was making the whole scene do anti-aliasing for me. That I found awkward - though given my weak GL-fu, it is likely I just did it wrong...

Anyway, with Glew and some later API calls, it worked out OK in the end!



Greg Ercolano

unread,
Oct 9, 2017, 5:57:37 PM10/9/17
to fltkg...@googlegroups.com
On 10/09/17 14:29, Ian MacArthur wrote:
> It wasn’t transparency, so much anyway, that I struggled with, it was
> making the whole scene do anti-aliasing for me. That I found awkward

Ah, sorry, anti-aliasing.. yes, I misread.
I must have read that as alpha rendering.

Mmm, I don't know if I've tried using antialiased rendering in opengl.
Would probably make a good example for the test/ or examples/ dirs.
I don't think I have a cheat sheet item for opengl with antialiased lines.

Alexey Balakin

unread,
Oct 10, 2017, 2:08:06 AM10/10/17
to fltk.general
Hi,

You can use Fl_MathGL widget from MathGL library (see http://mathgl.sourceforge.net/doc_en/Fl_005fMathGL-class.html). This is GPL (or LGPL with some restrictions) library for scientific plots. In particular, look at vector fields http://mathgl.sourceforge.net/doc_en/Vect-sample.html. At this you can use yours own background image as well.

Kind regards,
Alexey Balakin

понедельник, 9 октября 2017 г., 22:25:33 UTC+3 пользователь holm.h...@gmail.com написал:

holm.h...@gmail.com

unread,
Oct 10, 2017, 4:52:48 PM10/10/17
to fltk.general

Thank you Greg,

I like suggestion b) and will give it a try. It is for sure a possibility to do it in openGL, but that will cause rewriting large parts of my code.

I have been very happy with the performance of native fltk so far :-)

Best regards
Håvard

Reply all
Reply to author
Forward
0 new messages