pods::SDL::GFX::Primitives(3)

NAME
SDL::GFX::Primitives - basic drawing functions

CATEGORY
GFX

DESCRIPTION
All functions take an SDL::Surface object as first parameter. This can be a new surface that will be blitted afterwards, can be an surface obtained by SDL::Video::set_video_mode or can be an SDLx::App.

The "color" values for the "_color" functions are "0xRRGGBBAA" (32bit), even if the surface uses e. g. 8bit colors.

METHODS

  pixel
 int SDL::GFX::Primitives::pixel_color( $surface, $x, $y, $color );
 int SDL::GFX::Primitives::pixel_RGBA(  $surface, $x, $y, $r, $g, $b, $a );

Draws a pixel at point "x"/$y. You can pass the color by "0xRRGGBBAA" or by passing 4 values. One for red, green, blue and alpha.

 use SDL;
 use SDL::Video;
 use SDL::Surface;
 use SDL::GFX::Primitives;

 my $surface = SDL::Video::set_video_mode(640, 480, 32, SDL_SWSURFACE);

 SDL::GFX::Primitives::pixel_color($surface, 2, 2, 0xFF0000FF);             # red pixel
 SDL::GFX::Primitives::pixel_RGBA( $surface, 4, 4, 0x00, 0xFF, 0x00, 0xFF); # green pixel

  hline
 int SDL::GFX::Primitives::hline_color( $surface, $x1, $x2, $y, $color );
 int SDL::GFX::Primitives::hline_RGBA(  $surface, $x1, $x2, $y, $r, $g, $b, $a );

Draws a line horizontally from $x1/$y to $x2/$y.

  vline
 int SDL::GFX::Primitives::vline_color( $surface, $x, $y1, $y2, $color );
 int SDL::GFX::Primitives::vline_RGBA(  $surface, $x, $y1, $y2, $r, $g, $b, $a );

Draws a line vertically from $x/$y1 to $x/$y2.

  rectangle
 int SDL::GFX::Primitives::rectangle_color( $surface, $x1, $y1, $x2, $y2, $color );
 int SDL::GFX::Primitives::rectangle_RGBA(  $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );

Draws a rectangle. Upper left edge will be at $x1/$y1 and lower right at $x2/$y. The colored border has a width of 1 pixel.

  box
 int SDL::GFX::Primitives::box_color( $surface, $x1, $y1, $x2, $y2, $color );
 int SDL::GFX::Primitives::box_RGBA(  $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );

Draws a filled rectangle.

  line
 int SDL::GFX::Primitives::line_color( $surface, $x1, $y1, $x2, $y2, $color );
 int SDL::GFX::Primitives::line_RGBA(  $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );

Draws a free line from $x1/$y1 to $x2/$y.

  aaline
 int SDL::GFX::Primitives::aaline_color( $surface, $x1, $y1, $x2, $y2, $color );
 int SDL::GFX::Primitives::aaline_RGBA(  $surface, $x1, $y1, $x2, $y2, $r, $g, $b, $a );

Draws a free line from $x1/$y1 to $x2/$y. This line is anti aliased.

  circle
 int SDL::GFX::Primitives::circle_color( $surface, $x, $y, $r, $color );
 int SDL::GFX::Primitives::circle_RGBA(  $surface, $x, $y, $rad, $r, $g, $b, $a );

  arc
 int SDL::GFX::Primitives::arc_color( $surface, $x, $y, $r, $start, $end, $color );
 int SDL::GFX::Primitives::arc_RGBA(  $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );

Note: You need lib SDL_gfx 2.0.17 or greater for this function.

  aacircle
 int SDL::GFX::Primitives::aacircle_color( $surface, $x, $y, $r, $color );
 int SDL::GFX::Primitives::aacircle_RGBA(  $surface, $x, $y, $rad, $r, $g, $b, $a );

Note: You need lib SDL_gfx 2.0.17 or greater for this function.

  filled_circle
 int SDL::GFX::Primitives::filled_circle_color( $surface, $x, $y, $r, $color );
 int SDL::GFX::Primitives::filled_circle_RGBA(  $surface, $x, $y, $rad, $r, $g, $b, $a );

  ellipse
 int SDL::GFX::Primitives::ellipse_color( $surface, $x, $y, $rx, $ry, $color );
 int SDL::GFX::Primitives::ellipse_RGBA(  $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );

  aaellipse
 int SDL::GFX::Primitives::aaellipse_color( $surface, $xc, $yc, $rx, $ry, $color );
 int SDL::GFX::Primitives::aaellipse_RGBA(  $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );

  filled_ellipse
 int SDL::GFX::Primitives::filled_ellipse_color( $surface, $x, $y, $rx, $ry, $color );
 int SDL::GFX::Primitives::filled_ellipse_RGBA(  $surface, $x, $y, $rx, $ry, $r, $g, $b, $a );

  pie
 int SDL::GFX::Primitives::pie_color( $surface, $x, $y, $rad, $start, $end, $color );
 int SDL::GFX::Primitives::pie_RGBA(  $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );

This draws an opened pie. $start and $end are degree values. 0 is at right, 90 at bottom, 180 at left and 270 degrees at top.

  filled_pie
 int SDL::GFX::Primitives::filled_pie_color( $surface, $x, $y, $rad, $start, $end, $color );
 int SDL::GFX::Primitives::filled_pie_RGBA(  $surface, $x, $y, $rad, $start, $end, $r, $g, $b, $a );

  trigon
 int SDL::GFX::Primitives::trigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
 int SDL::GFX::Primitives::trigon_RGBA(  $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );

  aatrigon
 int SDL::GFX::Primitives::aatrigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
 int SDL::GFX::Primitives::aatrigon_RGBA(  $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );

  filled_trigon
 int SDL::GFX::Primitives::filled_trigon_color( $surface, $x1, $y1, $x2, $y2, $x3, $y3, $color );
 int SDL::GFX::Primitives::filled_trigon_RGBA(  $surface, $x1, $y1, $x2, $y2, $x3, $y3, $r, $g, $b, $a );

  polygon
 int SDL::GFX::Primitives::polygon_color( $surface, $vx, $vy, $n, $color );
 int SDL::GFX::Primitives::polygon_RGBA(  $surface, $vx, $vy, $n, $r, $g, $b, $a );

Example:

 SDL::GFX::Primitives::polygon_color($display, [262, 266, 264, 266, 262], [243, 243, 245, 247, 247], 5, 0xFF0000FF);

  aapolygon
 int SDL::GFX::Primitives::aapolygon_color( $surface, $vx, $vy, $n, $color );
 int SDL::GFX::Primitives::aapolygon_RGBA(  $surface, $vx, $vy, $n, $r, $g, $b, $a );

  filled_polygon
 int SDL::GFX::Primitives::filled_polygon_color( $surface, $vx, $vy, $n, $color );
 int SDL::GFX::Primitives::filled_polygon_RGBA(  $surface, $vx, $vy, $n, $r, $g, $b, $a );

  textured_polygon
 int SDL::GFX::Primitives::textured_polygon( $surface, $vx, $vy, $n, $texture, $texture_dx, $texture_dy );

  filled_polygon_MT
 int SDL::GFX::Primitives::filled_polygon_color_MT( $surface, $vx, $vy, $n, $color, $polyInts, $polyAllocated );
 int SDL::GFX::Primitives::filled_polygon_RGBA_MT(  $surface, $vx, $vy, $n, $r, $g, $b, $a, $polyInts, $polyAllocated );

Note: You need lib SDL_gfx 2.0.17 or greater for this function.

  textured_polygon_MT
 int SDL::GFX::Primitives::textured_polygon_MT( $surface, $vx, $vy, $n, $texture, $texture_dx, $texture_dy, $polyInts, $polyAllocated );

Note: You need lib SDL_gfx 2.0.17 or greater for this function.

  bezier
 int SDL::GFX::Primitives::bezier_color( $surface, $vx, $vy, $n, $s, $color );
 int SDL::GFX::Primitives::bezier_RGBA(  $surface, $vx, $vy, $n, $s, $r, $g, $b, $a );

$n is the number of elements in $vx and $vy, and $s is the number of steps. So the bigger $s is, the smother it becomes.

Example:

 SDL::GFX::Primitives::bezier_color($display, [390, 392, 394, 396], [243, 255, 235, 247], 4, 20, 0xFF00FFFF);

  character
 int SDL::GFX::Primitives::character_color( $surface, $x, $y, $c, $color );
 int SDL::GFX::Primitives::character_RGBA(  $surface, $x, $y, $c, $r, $g, $b, $a );

$c is the character that will be drawn at $x,$y.

  string
 int SDL::GFX::Primitives::string_color( $surface, $x, $y, $c, $color );
 int SDL::GFX::Primitives::string_RGBA(  $surface, $x, $y, $c, $r, $g, $b, $a );

  set_font
 void SDL::GFX::Primitives::set_font(fontdata, $cw, $ch );

The fontsets are included in the SDL_gfx distribution. Check <http://www.ferzkopp.net/joomla/content/view/19/14/> for more.

Example:

 my $font = '';
 open(FH, '<', 'data/5x7.fnt');
 binmode(FH);
 read(FH, $font, 4096);
 close(FH);

 SDL::GFX::Primitives::set_font($font, 5, 7);

AUTHORS
See "AUTHORS" in SDL.