#!/usr/bin/perl use strict; use warnings; use SDL; use SDL::Surface; use SDL::App; use SDL::Event; use Image::Magick; ## # Brücke von Image::Magic nach SDL ## sub magick_to_surface($) { my ($magick)=@_; my $depth=8; my $alpha=1; my @data=$magick->ImageToBlob(magick=>$alpha?'RGBA':'RGB', colorspace=>'RGB', depth=>$depth); my $b=$magick->Get('width'); my $h=$magick->Get('height'); return data_to_surface($data[0],$h,$b,$alpha,$depth) } ## # BiteString nach SDL ## sub data_to_surface($$$$$) { my ($data,$h,$b,$alpha,$colors)=@_; my $c=($colors*($alpha?4:3))/8; return SDL::Surface->new(-from =>$data, -width=>$b, -height=>$h, -depth=>$colors, -pitch=>$b*$c); } ## # Defaultbild erzeugen ## sub create_image($) { my ($img) = @_; $img->Set(size=>'100x100'); $img->Read('xc:none'); $img->Draw(fill=>'black', stroke=>"black", primitive=>'circle', points=>'50,50 2,50'); $img->Draw(fill=>'white', stroke=>"black", primitive=>'circle', points=>'50,50 5,50'); $img->Annotate(text=> '!', stroke=>"red", fill=>"red", x=>35, y=>85, pointsize=>100, font=>"arial"); } ################################################################### my $app = new SDL::App(-title => "Test", -width => 100, -height => 100, -depth => 8, -fullscreen => 0); my $images = Image::Magick->new; create_image($images); my $test=magick_to_surface($images); my $test_rect = new SDL::Rect( -x=>0, -y=>0, -width=>$test->width, -height=>$test->height ); $test->blit($test_rect, $app, $test_rect); $app->sync(); $app->loop({ SDL_QUIT() => sub { exit(0); } });