Does FLTK 1.4 support drawing gradients?

89 views
Skip to first unread message

Mark

unread,
Nov 30, 2021, 7:47:25 AM11/30/21
to fltk.general
Does FLTK 1.4 support drawing gradients? If so, can someone give me the link to the docs please?

Albrecht Schlosser

unread,
Nov 30, 2021, 8:54:10 AM11/30/21
to fltkg...@googlegroups.com
On 11/30/21 1:33 PM 'Mark' via fltk.general wrote:
> Does FLTK 1.4 support drawing gradients? If so, can someone give me
> the link to the docs please?

There's no builtin gradient support (yet).

It is possible that this will be added in the future because drawing
gradients line by line (as it is done now where gradients are used)
suffers from alignment issues with different zoom factors.

That said, you can see an example in the "gleam" scheme:
https://github.com/fltk/fltk/blob/master/src/fl_gleam.cxx

imm

unread,
Nov 30, 2021, 10:02:52 AM11/30/21
to General FLTK
Depending on what effect you are looking to achieve, it's probably also worth looking at the fltk SVG mechanism as that can draw fairly nice gradients too.

Or something using a fltk GL surface, I suppose.

Or (being deliberately obtuse!) I suppose, since you can draw individual pixels in a fltk draw method, you can "just" colour in the gradient "by hand"...

But there's no "built-in" fltk gradient mechanism...
--
Ian
From my Fairphone FP3

Mark

unread,
Nov 30, 2021, 11:37:17 AM11/30/21
to fltk.general
Thanks for your replies. I'll probably try doing my drawing in SVG and then displaying the results.

Greg Ercolano

unread,
Nov 30, 2021, 1:14:07 PM11/30/21
to fltkg...@googlegroups.com

On 11/30/21 8:27 AM, 'Mark' via fltk.general wrote:

Thanks for your replies. I'll probably try doing my drawing in SVG and then displaying the results.

    Yes, FLTK's native nanoSVG support is probably a good way to do a gradient..
    assuming nanoSVG supports gradients, I can't recall offhand but I think it does?

    nanoSVG is a subset of SVG, so has many limitations, but is great for doing
    certain things.

    You can basically create a text string of SVG code constructed procedurally,
    and pass it to nanosvg for rendering in a box. There's an example of that
    on the FLTK cheat page.

Mo_Al_

unread,
Nov 30, 2021, 1:36:34 PM11/30/21
to fltk.general
Just wanted to confirm that nanoSVG does support gradients.

janezz55

unread,
Dec 1, 2021, 11:34:25 AM12/1/21
to fltk.general
How about the CairoWidget?

Mark

unread,
Dec 2, 2021, 7:16:10 AM12/2/21
to fltk.general
Because I'm using fltk from rust I want to stick to rust libs. However, your point is valid and made me realise that I could use rust's image and imageproc libs to do the drawing onto in-memory PNG or whatever and then just paint the image.
Thanks.

janezz55

unread,
Dec 2, 2021, 9:35:54 AM12/2/21
to fltk.general
CairoWidget is simple and should be easy to port to rust. I am not sure, however, that rust compilers are able to generate the same high-quality shuffling code as c++ compilers can (clang in particular). That's essential for performance.

Albrecht Schlosser

unread,
Dec 2, 2021, 9:57:13 AM12/2/21
to fltkg...@googlegroups.com
On 12/2/21 2:46 PM janezz55 wrote:
> CairoWidget is simple and should be easy to port to rust.

Are you sure? I looked at the code in the (previously linked) repo and I
found that it's way too complicated to understand what it's actually doing.

I would have thought that such a "simple" issue might be solved by a
simple self-contained header file and maybe a short (self-contained as
well) implementation but this doesn't seem to be the case.

Are you the author? Please correct me if I'm wrong.

> I am not sure, however, that rust compilers are able to generate the
> same high-quality shuffling code as c++ compilers can (clang in
> particular). That's essential for performance.

I saw that it uses many C++ techniques which we can't use in the FLTK
core because of compatibility issues which precludes using it in the
FLTK core.

But if anybody wants to use it in their own (FLTK) code, that's probably
possible, I didn't want to say anything else.

janezz55

unread,
Dec 2, 2021, 12:04:33 PM12/2/21
to fltk.general
> Are you sure? I looked at the code in the (previously linked) repo and I
> found that it's way too complicated to understand what it's actually doing.

cairowidget.cpp has 99 lines and this is all that needs to be ported. The shuffler is separate for obvious reasons, but I've seen similar shuffling code in FLTK. The pixeliterator was an experiment to compare the iterator approach with the shuffler approach and is therefore irrelevant (the shuffler won). The rest is just cosmetics for superficial SVG, OpenGL and Qt support. It is possible to port these 99 lines all the way to C++98. Check out CairoWidget.cpp, the Qt version of CairoWidget, for an example; it is the same idea, adapted to Qt. The rust port might be a one-liner, for all I know.
Reply all
Reply to author
Forward
0 new messages