transparent polygon

27 views
Skip to first unread message

holm.h...@gmail.com

unread,
Aug 2, 2016, 4:25:08 AM8/2/16
to fltk.general


Hello,

Any plans for implementing transparent polygons ? Or is it this possible now ??

Best regards
Håvard Holm

Brian Tilley

unread,
Aug 2, 2016, 8:00:35 AM8/2/16
to fltkg...@googlegroups.com
It's certainly possible to draw transparent polygons in opengl. 

In FLTK I guess you'd just draw the polygon outline using multiple calls to fl_line()


On Tuesday, 2 August 2016, wrote:

Any plans for implementing transparent polygons ? Or is it this possible now ??

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Greg Ercolano

unread,
Aug 2, 2016, 1:18:52 PM8/2/16
to fltkg...@googlegroups.com
On 08/02/16 05:00, 'Brian Tilley' via fltk.general wrote:
> It's certainly possible to draw transparent polygons in opengl.

Yes; and you can do 2D compositing-like stuff that way,
e.g. using glDrawPixels() to draw the map, and then draw polys
over that with transparency.

Another technique would be to use pure non-transparent FLTK drawing
functions, draw the 'filled' area yourself by plotting non-transparent
dots in a halftone pattern, i.e. newsprint-screen-style, to achieve
pseudo-transparency. (see attached image).

This would mean, though, calculating the region of the polygon
to do your own custom 'fill'. Perhaps you can find the FLTK code
that draws the filled polygon, copy it into your code, and replace
the fill algorithm with a halftone pattern one.

halftone.jpg

Evan Laforge

unread,
Aug 2, 2016, 1:51:07 PM8/2/16
to fltkg...@googlegroups.com
I wrote this about 10 years ago, expecting performance would be awful and I'd have to come up with a real way eventually.   But it's still there.  Rects only though:

void alpha_rectf(IRect r, Color c)
{
    if (!fl_not_clipped(r.x, r.y, r.w, r.h))
        return;
    // If it has no alpha, don't bother.
    if (c.a == 0xff) {
        fl_color(c.fl());
        fl_rectf(r.x, r.y, r.w, r.h);
        return;
    }
    int nbytes = r.w * r.h * 4;
    // Don't crash if the caller wants a negative sized rect.
    if (nbytes <= 0)
        return;
    unsigned char *data = new unsigned char[nbytes];
    for (int i = 0; i < nbytes; i+=4) {
        data[i] = c.r;
        data[i+1] = c.g;
        data[i+2] = c.b;
        data[i+3] = c.a;
    }
    Fl_RGB_Image im(data, r.w, r.h, 4);
    im.draw(r.x, r.y);
    delete[] data;
}
Reply all
Reply to author
Forward
0 new messages