Drawing primitives are implemented in <lua_prim.c>. Header file is: <lua_prim.h>.

Most of drawing primitives routines are ready.

 

 

Drawing primitives

 

Most of functions from "Drawing Primitives" chapter accepts bitmap as a first parameter.

Bitmap is Lua userdata, and can be created by allegro.create_bitmap() or allegro.create_video_bitmap().

(see chapter "Bitmap Objects")

Notice: bitmap parameter can be omited or nil value can be passed instead in all functions that accept bitmap as a first parameter. 

In such case screen is assumed as a default parameter.

Example:

 

It is legal to call:

 

allegro.putpixel(myscreen,100,100,15)

In such case pixel will be drawn on "myscreen" bitmap, or if "myscreen" is nil then pixel will be drawn on the screen.

 

 

Second case:

 

allegro.putpixel(nil,100,100,15)

nil value is provided instead of valid bitmap. In such case pixel will be drawn on the screen.

 

 

Third case:

 

allegro.putpixel(100,100,15)

Bitmap parameter is omitted. In such case pixel will also be drawn on the screen.

 

 

 

allegro.clear_bitmap(userdata AL_BITMAP bitmap);

Clears the bitmap to color 0. 

Bitmap parameter is optional, it can be nil, or may be omitted. In such case, clear_bitmap(screen); will be called.

 

allegro.clearscreen( )

Shortcut for clear_bitmap(screen)

 

allegro.clear_to_color( bitmap , color )


Clears the bitmap to the specified color. 

Example:

 
      -- Clear the screen to red. 
      allegro.clear_to_color(screen,makecol(255,0,0))
 
allegro.putpixel( bitmap , x , y , color )

Writes a pixel to the specified position in the bitmap, using the current drawing mode and the bitmap's clipping rectangle. Example:
      allegro.putpixel(screen, 10, 30, some_color);
int color = allegro.getpixel(bitmap,x,y)

Reads a pixel from point (x, y) in the bitmap.

Return value: Returns -1 if the point lies outside the bitmap (ignoring the clipping rectangle), otherwise the value of the pixel in the color format of the bitmap.

Warning: -1 is also a valid value for pixels contained in 32-bit bitmaps with alpha channel (when R,G,B,A are all equal to 255) so you can't use the test against -1 as a predicate for such bitmaps. In this cases, the only reliable predicate is allegro.is_inside_bitmap().

 

 

allegro.vline(bitmap , x , y1 , y2 , color )

Draws a vertical line onto the bitmap, from point (x, y1) to (x, y2).

Note: vline() is implemented as an alias to another function. See ALLEGRO_NO_VHLINE_ALIAS in the `Differences between platforms' section for details. (Look in Allegro help http://www.talula.demon.co.uk/allegro/

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).

Note: hline() is implemented as an alias to another function. See ALLEGRO_NO_VHLINE_ALIAS in the `Differences between platforms' section for details. (Look in Allegro help http://www.talula.demon.co.uk/allegro/

This function is not implemented yet.

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(). Example:
      void draw_dust_particle(BITMAP *bmp, int x, int y, int d)
      {
         ...
      }
      
         do_line(screen, 0, 0, SCREEN_W-1, SCREEN_H-2,
                 dust_strength, draw_dust_particle);
See also: do_circle, do_ellipse, do_arc, line.
allegro.line( bitmap , x1 , y1 , x2 , y2 , color )

Draws a line onto the bitmap, from point (x1, y1) to (x2, y2).

 

See also: fastline, hline, vline, do_line, drawing_mode, makecol.
allegro.triangle( bitmap , x1 , y1 , x2 , y2 , x3 , y3 , color )

Draws a filled triangle between the three points.
See also: polygon, triangle3d, drawing_mode, makecol.
allegro.polygon(bitmap, table vertices, int color);

Draws a filled polygon with an arbitrary number of corners. Pass the array "vertices" in one of three possible formats:

 

a):

vertices={{x=100,y=100},{x=200,y=130}, ... ,{x=130,y=200}}

or

b):

vertices={{100,100},{200,130}, ... ,{130,200}}

or

c):

vertices={100,100,200,130, ... ,130,200}

 

All three ways of passing vertices coordinates are legal and will be detected automatically.

Third way is tricky. Number of items in a table must be even.

 Example:

      
      allegro.clear_to_color(screen, makecol(255, 255, 255));
      allegro.polygon(screen, { 50, 50,   100, 100,  100, 150,
                        50, 200,  0,   150,  0,   100 }, makecol(0, 0, 0));
 
allegro.rect( bitmap , x1 , y1 , x2 , y2 , color )

Draws an outline rectangle with the two points as its opposite corners.

 

allegro.rectfill( bitmap , x1 , y1 , x2 , y2 , color )

Draws a solid, filled rectangle with the two points as its opposite corners.
See also: rect, clear_bitmap, drawing_mode, makecol.

This is not implemented yet. I imagine that this function should return table of vertices.

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(). Example:
      void draw_explosion_ring(BITMAP *bmp, int x, int y, int d)
      {
         ...
      }
      
         do_circle(screen, SCREEN_W/2, SCREEN_H/2,
                   SCREEN_H/16, flame_color,
                   draw_explosion_ring);
See also: do_ellipse, do_arc, do_line, circle, circlefill.
allegro.circle( bitmap , x , y , radius , color )

Draws a circle with the specified centre and radius.
See also: ellipse, arc, circlefill, do_circle, drawing_mode, makecol.
allegro.circlefill( bitmap , x , y , radius , color )

Draws a filled circle with the specified centre and radius.
See also: ellipsefill, circle, do_circle, drawing_mode, makecol.
Examples using this: excolmap, excustom, exdbuf, exflip, exlights, expal, exspline, extrans.

This is not implemented yet. I imagine that this function should return table of vertices.

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(). Example:
      void draw_explosion_ring(BITMAP *bmp, int x, int y, int d)
      {
         ...
      }
      
         do_ellipse(screen, SCREEN_W/2, SCREEN_H/2,
                   SCREEN_H/16, SCREEN_H/32, flame_color,
                   draw_explosion_ring);
See also: do_circle, do_arc, do_line, ellipse, ellipsefill.
allegro.ellipse( bitmap , x , y , rx , ry , color )

Draws an ellipse with the specified centre and radius.
See also: circle, arc, ellipsefill, do_ellipse, drawing_mode, makecol.
allegro.ellipsefill(bitmap , x , y , rx , ry , color )

Draws a filled ellipse with the specified centre and radius.
See also: circlefill, ellipse, do_ellipse, drawing_mode, makecol.

This is not implemented yet. I imagine that this function should return table of vertices.

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. Example:
      void draw_explosion_ring(BITMAP *bmp, int x, int y, int d)
      {
         ...
      }
         arc(screen, SCREEN_W/2, SCREEN_H/2,
             itofix(-21), itofix(43), 50, flame_color,
             draw_explosion_ring);
See also: do_circle, do_ellipse, do_line, arc.
allegro.arc( bitmap , x , y , angle_1 , angle_2 , radius , 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. 

Angles are specified in degrees (full angle is 360 degrees) and may contain fraction parts of a degree.(Maybe future implementations should allow also radians) Zero is to the right of the centre point, and larger values rotate anticlockwise from there. 

See also: circle, ellipse, drawing_mode, makecol.

This is not implemented yet. I imagine that this function should return table of vertices.

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.
allegro.spline( bitmap , table points , color)

Draws a bezier spline using the four control points specified in the points array. Points are in the same format as "vertices" in the polygon routine. That means three formats are allowed. See allegro.polygon() for details.

 

See also: calc_spline, drawing_mode, makecol.
Examples using this: exspline.
allegro.floodfill( bitmap , x , y , color )

Floodfills an enclosed area, starting at point (x, y), with the specified color.
See also: drawing_mode, makecol.

Back to main page