#!/usr/bin/perl use warnings; use strict; use SDL; use SDL::Video; use SDLx::App; use SDL::GFX::Primitives; sub drawPolygon { my ($window, $color, $x1, $y1, $w1, $x2, $y2, $w2) = @_; my @points = ([$x1 - $w1, $y1], [$x2 - $w2, $y2], [$x2 + $w2, $y2], [$x1 + $w1, $y1]); my $pointnr = @points; my $i; my @xs = (); my @ys = (); foreach $i (@points) { my @arr = @{$i}; push(@xs, $arr[0]); push(@ys, $arr[1]); } my $xsref = \@xs; my $ysref = \@ys; SDL::GFX::Primitives::filled_polygon_color($window, $xsref, $ysref, $pointnr, $color); $window->update(); } sub rgbToHexColor { my ($r, $g, $b) = @_; # 64 for Alpha = 100: return sprintf("0x%02lX%02lX%02lX64", $r, $g, $b); } SDL::init(SDL_INIT_VIDEO); my $app = SDLx::App->new( title => "Polygon", width => 1024, height => 768, dt => 0.2, depth => 16, ); drawPolygon($app, hex(rgbToHexColor(0, 255, 0)), 500, 500, 200, 500, 300, 100); sleep(5);