[Previous] [Contents] [Index] [Next]

PgDrawPolygon(), PgDrawPolygonmx()

Draw a stroked and/or filled polygon

Synopsis:

int  PgDrawPolygon( PhPoint_t const *ptr,
                    int num,
                    PhPoint_t const *pos,
                    int flags );

int  PgDrawPolygonmx( PhPoint_t const *ptr,
                      int num,
                      PhPoint_t const *pos,
                      int flags );

Description:

These functions build a command in the draw buffer to draw a polygon from an array of points, pointed to by ptr, with num entries.


Note: The array of points must fit in the draw buffer, even if you use PgDrawPolygonmx().

The flags argument must be one of the following:

Pg_DRAW_STROKE
Draw a stroked polygon.
Pg_DRAW_FILL
Draw a filled polygon.
Pg_DRAW_FILL_STROKE
Draw a filled polygon, then stroke it.

You can OR flags with any combination of the following:

Pg_CLOSED
Connect the last point to the first.
Pg_RELATIVE
Use relative coordinates to draw the polygon. Each point is relative to the previous point.

For absolute coordinates, pos is added to each point pointed to by ptr. For relative coordinates, the first coordinate is the sum of pos and the first point of the array; any subsequent coordinate is the sum of the previous point and the next point of the array.


Note: If you call the "mx" form of this function, the data isn't physically copied into the draw buffer. Instead, a pointer to the array is stored until the draw buffer is flushed. Make sure you call PgFlush() before you modify the point array.

Returns:

0
Successful completion
-1
The draw buffer is too small to hold the current draw state, the draw command, and the data. Increase the size of the draw buffer or decrease the number of points.

Examples:

The following example:

DrawFillStrokePoly() {
    PhPoint_t   o = { 0, 0 };
    PhPoint_t   p[] = { 80, 8, 120, 120, 16, 32, 
                        136, 32, 40, 120 };

    PgSetStrokeColor( Pg_WHITE );
    PgSetFillColor( Pg_PURPLE );
    PgDrawPolygon( &p, 5, &o, Pg_DRAW_FILL_STROKE | 
                                      Pg_CLOSED );
}

will draw:

PgDrawPolygon,fillstroke

The following example:

DrawRelPoly() {
    PhPoint_t   o = { 0, 0 };
    PhPoint_t   p[] = { 80, 8, 40, 112, -104, -88, 
                        120, 0, -96, 88 };

    PgSetStrokeColor( Pg_WHITE );
    PgSetFillColor( Pg_PURPLE );
    PgDrawPolygon( &p, 5, &o, Pg_DRAW_FILL_STROKE | 
                                        Pg_CLOSED | 
                                        Pg_RELATIVE );
}

will draw:

PgDrawPolygon,relative

The following example:

DrawUnclosedPoly() {
    PhPoint_t   o = { 0, 0 };
    PhPoint_t   p[] = { 80, 8, 120, 120, 16, 32, 
                        136, 32, 40, 120 };

    PgSetStrokeColor( Pg_WHITE );
    PgSetFillColor( Pg_PURPLE );
    PgDrawPolygon( &p, 5, &o, Pg_DRAW_FILL_STROKE );
}

will draw:

PgDrawPolygon,unclosed

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PgFlush()

To draw stroked polygons, see also:

PgSetStrokeColor(), PgSetStrokeCap(), PgSetStrokeDash(), PgSetStrokeDither(), PgSetStrokeJoin(), PgSetStrokeWidth()

To draw filled polygons, see also:

PgSetFillColor(), PgSetFillDither(), PgSetFillTransPat()


[Previous] [Contents] [Index] [Next]