Caution: This version of this document is no longer maintained. For the latest documentation, see

PgSetFillDither(), PgSetFillDitherCx()

Set the dither pattern and colors for fills


void PgSetFillDither( PgColor_t c1,
                      PgColor_t c0,
                      PgPattern_t pat );

void PgSetFillDitherCx( PhGC_t *gc,
                        PgColor_t c1,
                        PgColor_t c0,
                        PgPattern_t pat );




These functions combine two colors according to the pattern defined by pat and applies the pattern to fills.

The c1 argument represents the color used for “on” bits in the dither pattern and c0 represents the color used for “off” bits. The driver always selects the colors closest to c1 and c0.

The dither pattern is an array of 8 bytes, aligned with the upper-left corner of the application's region. This pattern repeats itself every 8 pixels horizontally and every 8 pixels vertically.

These functions override the color defined by the appropriate PgSetFillColor() function. For basic colors, see PgColor_t.

At least the following patterns are defined in <photon/Pg.h>:


Predefined dither patterns.

PgSetFillDither() works on the current graphics context, while you can specify the graphics context gc for PgSetFillDitherCx().


// Set the fill to be black with every 8th
// vertical line being white
PgSetFillDither( Pg_WHITE, Pg_BLACK, Pg_PAT_VERT8 );

// Set the fill to be red bricks with dark gray mortar
PgSetFillDither(Pg_DGRAY, Pg_RED,
                "\x20\x20\xFF\x02\x02\x02\xFF\x20" );

Here's the code that produced the sample of predefined dither patterns:

typedef struct {
    char        *name;
    PgPattern_t p;
} DithersListStruct;

DithersListStruct DithersList[] = {
    "Pg_PAT_HALF",          Pg_PAT_HALF,
    "Pg_PAT_CHECKB8",       Pg_PAT_CHECKB8,
    "Pg_PAT_CHECKB4",       Pg_PAT_CHECKB4,
    "Pg_PAT_HORIZ8",        Pg_PAT_HORIZ8,
    "Pg_PAT_HORIZ4",        Pg_PAT_HORIZ4,
    "Pg_PAT_HORIZ2",        Pg_PAT_HORIZ2,
    "Pg_PAT_VERT8",         Pg_PAT_VERT8,
    "Pg_PAT_VERT4",         Pg_PAT_VERT4,
    "Pg_PAT_VERT2",         Pg_PAT_VERT2,
    "Pg_PAT_DIAGF8",        Pg_PAT_DIAGF8,
    "Pg_PAT_DIAGF4",        Pg_PAT_DIAGF4,
    "Pg_PAT_DIAGB8",        Pg_PAT_DIAGB8,
    "Pg_PAT_DIAGB4",        Pg_PAT_DIAGB4,
    "Pg_PAT_BRICK",         Pg_PAT_BRICK,
    "Pg_PAT_WEAVE",         Pg_PAT_WEAVE,
    "Pg_PAT_RXHATCH8",      Pg_PAT_RXHATCH8,
    "Pg_PAT_RXHATCH4",      Pg_PAT_RXHATCH4,
    "Pg_PAT_RXHATCH2",      Pg_PAT_RXHATCH2,
    "Pg_PAT_DXHATCH8",      Pg_PAT_DXHATCH8,
    "Pg_PAT_DXHATCH4",      Pg_PAT_DXHATCH4,


#define DithersListNum \
     (sizeof( DithersList ) / sizeof( DithersListStruct ) )
#define DithersListCHeight  20
#define DithersListWinY     (DithersListNum*DithersListCHeight)

Dithers() {
    DithersListStruct   *DLPtr = DithersList;
    PhPoint_t   p;
    PhRect_t    r;
    int i, y;
    char Helvetica14b[MAX_FONT_TAG];

    if(PfGenerateFontName("Helvetica", PF_STYLE_BOLD, 14,
                          Helvetica14b) == NULL) {
        perror("Unable to find font");
    } else {
        PgSetFont( Helvetica14b );
    PgSetTextColor( Pg_BLACK );
    PgSetStrokeColor( Pg_BLACK );
    for (y=i=0; i<DithersListNum;
         i++, y+=DithersListCHeight, DLPtr++) {
        p.x = 2;
        p.y = y+14;
        PgDrawText( DLPtr->name,
                    strlen( DLPtr->name ), &p, 0 );
        PgSetFillDither( Pg_WHITE, Pg_DBLUE, DLPtr->p );
        r.ul.x = 160; = 320;
        r.ul.y = y; = y+DithersListCHeight;
        PgDrawRect( &r, Pg_DRAW_FILL_STROKE );



Interrupt handler No
Signal handler No
Thread No

See also:

PgARGB(), PgCMY(), PgColor_t, PgDefaultFill*(), PgGray(), PgHSV(), PgRGB(), PgSetFillColor*(), PgSetFillTransPat*(), PgSetFillXORColor*(), PgSetStrokeDither*(), PgSetTextDither*()

Drawing attributes and Arcs, ellipses, polygons, and rectangles in the Raw Drawing and Animation chapter of the Photon Programmer's Guide