# Drawing primitives

- _getpixel
- _getpixel15
- _getpixel16
- _getpixel24
- _getpixel32
- _putpixel
- _putpixel15
- _putpixel16
- _putpixel24
- _putpixel32
- arc
- calc_spline
- circle
- circlefill
- do_arc
- do_circle
- do_ellipse
- do_line
- ellipse
- ellipsefill
- floodfill
- getpixel
- hline
- line
- polygon
- putpixel
- rect
- rectfill
- spline
- triangle
- vline

Except for _putpixel(), all these routines are affected by the current drawing mode and the clipping rectangle of the destination bitmap.

void putpixel(BITMAP *bmp, int x, int y, int color);
Writes a pixel to the specified position in the bitmap, using the current drawing mode and the bitmap's clipping rectangle.

> See also: getpixel, _putpixel, drawing_mode.

> Examples using this: ex12bit, exalpha, exflame, exjoy, exstars, exswitch.

void _putpixel(BITMAP *bmp, int x, int y, int color);
void _putpixel15(BITMAP *bmp, int x, int y, int color);
void _putpixel16(BITMAP *bmp, int x, int y, int color);
void _putpixel24(BITMAP *bmp, int x, int y, int color);
void _putpixel32(BITMAP *bmp, int x, int y, int color);
Like the regular putpixel(), but much faster because they are implemented as an inline assembler functions for specific color depths. These won't work in mode-X graphics modes, don't perform any clipping (they will crash if you try to draw outside the bitmap!), and ignore the drawing mode.

> See also: putpixel.

int getpixel(BITMAP *bmp, int x, int y);
Reads a pixel from point x, y in the bitmap. Returns -1 if the point lies outside the bitmap.

> See also: putpixel, _getpixel.

> Examples using this: ex12bit, exalpha, exflame, exlights.

int _getpixel(BITMAP *bmp, int x, int y);
int _getpixel15(BITMAP *bmp, int x, int y);
int _getpixel16(BITMAP *bmp, int x, int y);
int _getpixel24(BITMAP *bmp, int x, int y);
int _getpixel32(BITMAP *bmp, int x, int y);
Faster inline versions of getpixel() for specific color depths. These won't work in mode-X, and don't do any clipping, so you must make sure the point lies inside the bitmap.

> See also: getpixel.

void vline(BITMAP *bmp, int x, int y1, int y2, int color);
Draws a vertical line onto the bitmap, from point (x, y1) to (x, y2).

> See also: hline, line, drawing_mode.

> Examples using this: exrgbhsv, exscroll, extruec.

void hline(BITMAP *bmp, int x1, int y, int x2, int color);
Draws a horizontal line onto the bitmap, from point (x1, y) to (x2, y).

> See also: vline, line, drawing_mode.

void do_line(BITMAP *bmp, int x1, y1, x2, y2, int d, void (*proc)(BITMAP *bmp, int x, int y, int d));
Calculates all the points along a line from point (x1, y1) to (x2, y2), calling the supplied function for each one. This will be passed a copy of the bmp parameter, the x and y position, and a copy of the d parameter, so it is suitable for use with putpixel().

> See also: do_circle, do_ellipse, do_arc, line.

void line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
Draws a line onto the bitmap, from point (x1, y1) to (x2, y2).

> See also: hline, vline, do_line, drawing_mode.

> Examples using this: Available Allegro examples.

void triangle(BITMAP *bmp, int x1, y1, x2, y2, x3, y3, int color);
Draws a filled triangle between the three points.

> See also: polygon, triangle3d, drawing_mode.

> Examples using this: ex3buf, exstars, exupdate.

void polygon(BITMAP *bmp, int vertices, const int *points, int color);
Draws a filled polygon with an arbitrary number of corners. Pass the number of vertices and an array containing a series of x, y points (a total of vertices*2 values).

> See also: triangle, polygon3d, drawing_mode.

> Examples using this: excamera.

void rect(BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
Draws an outline rectangle with the two points as its opposite corners.

> See also: rectfill, drawing_mode.

> Examples using this: ex3d, excamera.

void rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color);
Draws a solid, filled rectangle with the two points as its opposite corners.

> See also: rect, clear_bitmap, drawing_mode.

> Examples using this: exalpha, excolmap, exkeys, expat, exscroll, exsprite, exstars, exswitch, extrans.

void do_circle(BITMAP *bmp, int x, int y, int radius, int d, void (*proc)(BITMAP *bmp, int x, int y, int d));
Calculates all the points in a circle around point (x, y) with radius r, calling the supplied function for each one. This will be passed a copy of the bmp parameter, the x and y position, and a copy of the d parameter, so it is suitable for use with putpixel().

> See also: do_ellipse, do_arc, do_line, circle, circlefill.

void circle(BITMAP *bmp, int x, int y, int radius, int color);
Draws a circle with the specified centre and radius.

> See also: ellipse, arc, circlefill, do_circle, drawing_mode.

> Examples using this: ex12bit, exblend, excustom, exjoy, exmem, exmouse, exquat.

void circlefill(BITMAP *bmp, int x, int y, int radius, int color);
Draws a filled circle with the specified centre and radius.

> See also: ellipsefill, circle, do_circle, drawing_mode.

> Examples using this: excolmap, excustom, exdbuf, exflip, exlights, expal, exspline, extrans.

void do_ellipse(BITMAP *bmp, int x, int y, int rx, ry, int d, void (*proc)(BITMAP *bmp, int x, int y, int d));
Calculates all the points in an ellipse around point (x, y) with radius rx and ry, calling the supplied function for each one. This will be passed a copy of the bmp parameter, the x and y position, and a copy of the d parameter, so it is suitable for use with putpixel().

> See also: do_circle, do_arc, do_line, ellipse, ellipsefill.

void ellipse(BITMAP *bmp, int x, int y, int rx, int ry, int color);
Draws an ellipse with the specified centre and radius.

> See also: circle, arc, ellipsefill, do_ellipse, drawing_mode.

void ellipsefill(BITMAP *bmp, int x, int y, int rx, int ry, int color);
Draws a filled ellipse with the specified centre and radius.

> See also: circlefill, ellipse, do_ellipse, drawing_mode.

> Examples using this: ex12bit.

void do_arc(BITMAP *bmp, int x, int y, fixed a1, fixed a2, int r, int d, void (*proc)(BITMAP *bmp, int x, int y, int d));
Calculates all the points in a circular arc around point (x, y) with radius r, calling the supplied function for each one. This will be passed a copy of the bmp parameter, the x and y position, and a copy of the d parameter, so it is suitable for use with putpixel(). The arc will be plotted in an anticlockwise direction starting from the angle a1 and ending when it reaches a2. These values are specified in 16.16 fixed point format, with 256 equal to a full circle, 64 a right angle, etc. Zero is to the right of the centre point, and larger values rotate anticlockwise from there.

> See also: do_circle, do_ellipse, do_line, arc.

void arc(BITMAP *bmp, int x, y, fixed ang1, ang2, int r, int color);
Draws a circular arc with centre x, y and radius r, in an anticlockwise direction starting from the angle a1 and ending when it reaches a2. These values are specified in 16.16 fixed point format, with 256 equal to a full circle, 64 a right angle, etc. Zero is to the right of the centre point, and larger values rotate anticlockwise from there.

> See also: circle, ellipse, drawing_mode.

void calc_spline(const int points[8], int npts, int *x, int *y);
Calculates a series of npts values along a bezier spline, storing them in the output x and y arrays. The bezier curve is specified by the four x/y control points in the points array: points[0] and points[1] contain the coordinates of the first control point, points[2] and points[3] are the second point, etc. Control points 0 and 3 are the ends of the spline, and points 1 and 2 are guides. The curve probably won't pass through points 1 and 2, but they affect the shape of the curve between points 0 and 3 (the lines p0-p1 and p2-p3 are tangents to the spline). The easiest way to think of it is that the curve starts at p0, heading in the direction of p1, but curves round so that it arrives at p3 from the direction of p2. In addition to their role as graphics primitives, spline curves can be useful for constructing smooth paths around a series of control points, as in exspline.c.

> See also: spline.

> Examples using this: exspline.

void spline(BITMAP *bmp, const int points[8], int color);
Draws a bezier spline using the four control points specified in the points array.

> See also: calc_spline, drawing_mode.

> Examples using this: exspline.

void floodfill(BITMAP *bmp, int x, int y, int color);
Floodfills an enclosed area, starting at point (x, y), with the specified color.

> See also: drawing_mode.

Back to contents