Esempio n. 1
0
void gl_color(Fl_Color i)
{
    #if USE_GL_OVERLAY
    #ifndef _WIN32
    if (fl_overlay) {glIndexi(int(fl_xpixel(i))); return;}
    #else
    if (fl_overlay && fl_overlay_depth)
    {
        i = fl_nearest_color(i); // convert to 8-bit color
        if (fl_overlay_depth < 8)
        {
            // only black & white produce the expected colors.  This could
            // be improved by fixing the colormap set in Fl_Gl_Overlay.cxx
            unsigned size = 1<<fl_overlay_depth;
            if (!i) glIndexi(size-2);
            else if (i >= size-2) glIndexi(size-1);
            else glIndexi(i);
        }
        else
        {
            glIndexi(i ? i : FL_GRAY_RAMP);
        }
        return;
    }
    #endif
    #endif
    Fl_Color c = fl_get_color(i);
    glColor3ub((uchar)(c>>24), (uchar)(c>>16), (uchar)(c>>8));
}
Esempio n. 2
0
ulong fl_xpixel(Fl_Color i)
{
    if (!beenhere) figure_out_visual();

#if USE_COLORMAP
#if USE_OVERLAY | USE_GL_OVERLAY
    if (fl_redmask && !fl_overlay)
#else
        if (fl_redmask)
#endif
    {
#endif
        // return color for a TrueColor visual:
        if (!(i & 0xFFFFFF00)) i = (Fl_Color)fl_cmap[i];
        return
            ((((i>>24)& fl_redmask)  << fl_redshift)+
            (((i>>16)& fl_greenmask)<< fl_greenshift)+
            (((i>>8) & fl_bluemask) << fl_blueshift)
            ) >> fl_extrashift;
#if USE_COLORMAP
    }

    // rest of this is for a colormapped visual (it will work for a TrueColor
    // visual but wastes time):

    // translate rgb colors into color index:
    int index = fl_nearest_color(i);

    // see if we have already allocated it:
#if USE_OVERLAY | USE_GL_OVERLAY
    Fl_XColor &xmap = fl_overlay ? fl_overlay_xmap[index] : fl_xmap[index];
#else
    Fl_XColor &xmap = fl_xmap[index];
#endif
    if (!xmap.mapped)
    {
        // figure out the rgb to ask for.  Use the specified one unless this
        // is an indexed color, in which case we use the colormap entry:
        if (!(i & 0xFFFFFF00)) i = (Fl_Color)fl_cmap[i];
        uchar r = i>>24;
        uchar g = i>>16;
        uchar b = i>> 8;
        fl_allocate_xpixel(xmap, r, g, b);
    }
    return xmap.pixel;
}