Thread [SDL] Raute und Polygone zeichnen? (5 answers)
Opened by hlubenow at 2018-01-27 11:59

hlubenow
 2018-01-27 20:24
#187954 #187954
User since
2009-02-22
837 articles
BenutzerIn
[default_avatar]
Ja, das hat funktioniert:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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);

View full thread [SDL] Raute und Polygone zeichnen?