transparency for drawing in fltk 1.5 on linux with X11/wayland

26 views
Skip to first unread message

Klaus Rudolph

unread,
Nov 9, 2025, 6:27:26 AMNov 9
to fltk.general
Hi again!

Can we use transparency for drawing in fltk 1.5?

The function fl_can_do_alpha_blending() returns 1 on my system.
But looking in the docs tells me that color values for fl_color are in RGBI and not RGBA or something like that.

Is there already an interface to set the RGBA values or maybe transparency alone in some kind for drawing shapes in the draw() function of the windows/widgets?

Regards
 Klaus

Matthias Melcher

unread,
Nov 9, 2025, 7:18:34 AMNov 9
to fltk.general
There is minimal support for transparency in 1.4 already. You can draw images with alpha channel to composite graphics, and you can assign an alpha value to colors in the color lookup table, but I think this is currently only supported if you draw widgets inside an OpenGL window. You can make the background color of the widget semi transparent, and the OpenGL graphics will "shine through" your widget.

So, yes, I would love to support alpha blending. The first thing we would need to do is define and API that is useful for GUI programming. As you said, the alpha component of RGBA data is already used in FLTK for the color index. Any suggestions for the API?

Manolo

unread,
Nov 9, 2025, 7:52:03 AMNov 9
to fltk.general
See also Fl::set_color(Fl_Color i, uchar r, uchar g, uchar b, uchar a) that allows to 
set an entry in the fl_color index table to any 8-bit RGBA color with the following caveat:
  The color transparency is effective under the Wayland, hybrid Wayland/X11 and macOS 
  platforms, whereas it has no effect under the X11 and Windows platforms. It's also 
  effective for widgets added to an Fl_Gl_Window.

imm

unread,
Nov 9, 2025, 8:25:49 AMNov 9
to General FLTK
I'd also mention shaped window support at this point, just in case that's useful for the OP's (Klaus) use case.

A while back, someone was asking here about transparency, but in practice it turned out what they really wanted was shaped windows, so this may be pertinent.

--
Ian
From my Fairphone FP3

Klaus Rudolph

unread,
Nov 9, 2025, 8:50:24 AMNov 9
to fltk.general
I tried the following:
#include <FL/Fl_Window.H>
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>

#include <iostream>


class MyWin: public Fl_Window
{
    public:
        //using Fl_Window::Fl_Window;
        MyWin( int x, int y, int w, int h, const char* title = 0 ):
            Fl_Window(x,y,w,h,"Hallo Welt!")
    {  
    }  

        void draw() override
        {
            Fl_Window::draw();
            std::cout << "Draw!" << std::endl;

            Fl::set_color(1, 0xff, 0x0, 0x0, 0x80 );
            Fl::set_color(2, 0x00, 0xff, 0x0, 0x80 );
            fl_line_style( FL_SOLID, 20 );
            fl_color(1);
            fl_line( 10,10,100,100 );
            fl_color(2);
            fl_line( 10,100,100,10 );
        }
};


int main()
{
    auto win = new MyWin(1,1,900, 600, "Test");
    win->show();

    Fl::run();
}

But I can't see any transparency. I expected some effects on the line crossing but the green line is simply drawn over the red one. What I did wrong?

Regards
 Klaus

Manolo

unread,
Nov 9, 2025, 8:58:34 AMNov 9
to fltk.general
Did you use Windows or X11 without Cairo? As written above, there's no transparency support in these cases.

Klaus Rudolph

unread,
Nov 9, 2025, 9:20:54 AMNov 9
to fltk.general
Sorry!

Your sentence: "
The color transparency is effective under the Wayland, hybrid Wayland/X11 and macOS 
  platforms, whereas it has no effect under the X11 and Windows platforms."

is totally confusing me! 

I also had the same trouble by finding out what X11 with and without Xft and hybrid or non hybrid things is doing....
I am not an X11 expert. I want to use my app under X11 and wayland in best case with one binary only.

As mentioned in another thread I did not know how I had compiled fltk because this information was lost.
So I try to compile fltk again now with explicit enable cairo...

Sorry for my confusion, but all the X11 vs wayland and also the big catalogue of used or not used libs is new to me. I used tcl/tk and gtk a lot without directly dealing with the underlying libs directly.

Regards
 Klaus

Manolo

unread,
Nov 9, 2025, 9:28:11 AMNov 9
to fltk.general
> I want to use my app under X11 and wayland in best case with one binary only.

Then, you are in a favorable situation. If FLTK is built with all default settings under Linux
you obtain support for Wayland and for X11 with Cairo with one binary. Thus, you also obtain
transparency support via the Fl::set_color() function mentioned above.

Klaus Rudolph

unread,
Nov 9, 2025, 9:34:55 AMNov 9
to fltk.general
I now compiled fltk 1.5 with:
git clone https://github.com/fltk/fltk fltk_1.5.x_cairo
cd fltk_1.5.x_cairo
cmake . -B mybuild -D FLTK_GRAPHICS_CAIRO=ON -D CMAKE_BUILD_TYPE=Debug -D FLTK_BUILD_EXAMPLES=ON -D CMAKE_INSTALL_PREFIX:PATH=/home/krud/external_repos/fltk-1.5.x_cairo/myinstall
cmake --build mybuild -j12
cmake --install mybuild

After rebuild my app transparency is available!

Maybe some other user runs into the same confusion and needs also enable cairo :-)

Thanks for the support!
 Regards
  Klaus

Manolo

unread,
Nov 9, 2025, 9:39:12 AMNov 9
to fltk.general
Le dimanche 9 novembre 2025 à 15:34:55 UTC+1, Klaus Rudolph a écrit :
I now compiled fltk 1.5 with:
git clone https://github.com/fltk/fltk fltk_1.5.x_cairo
cd fltk_1.5.x_cairo
cmake . -B mybuild -D FLTK_GRAPHICS_CAIRO=ON -D CMAKE_BUILD_TYPE=Debug -D FLTK_BUILD_EXAMPLES=ON -D CMAKE_INSTALL_PREFIX:PATH=/home/krud/external_repos/fltk-1.5.x_cairo/myinstall
cmake --build mybuild -j12
cmake --install mybuild

After rebuild my app transparency is available!

Good. And I add that  -D FLTK_GRAPHICS_CAIRO=ON should not be necessary because the default setting
gives the same result.

Klaus Rudolph

unread,
Nov 9, 2025, 10:08:13 AMNov 9
to fltk.general
I am wondering! It looks like, that it was not auto enabled during my last build. And the README.CMake.txt tells us "FLTK_GRAPHICS_CAIRO - default OFF". No idea what is wrong or right?

Manolo

unread,
Nov 9, 2025, 1:50:13 PMNov 9
to fltk.general
It's very difficult to detail in few words the effect and the default values of
build option FLTK_GRAPHICS_CAIRO. The same file also indicates:
When using Wayland this option is always ON.

Normally, you should get the same result with and without -D FLTK_GRAPHICS_CAIRO=ON
on a modern Linux system unless you set -D FLTK_BACKEND_WAYLAND=OFF or software packages
necessary for Wayland are not present on the system. 
At any rate, it's not wrong to set this option explicitly ON.

Reply all
Reply to author
Forward
0 new messages