Hello!
How can I print out a text in a simple application-window?
Here is my non-working test-code:
#!/Perl/bin/perl
use strict;
use warnings;
use SDL;
use SDL::App;
use SDL::Rect;
use SDL::Color;
use SDL::Surface;
use SDL::Tool::Font;
use SDL::TTFont;############################################################
Definieren der Elemente des Programms
############################################################
my $app = new SDL::App (
-title => ‘Animation’,
-width => 640,
-height => 480,
-depth => 32,
);
my $color = SDL::Color->new(
-r => 0x00,
-g => 0x00,
-b => 0xff,
);
my %rect = (); # alle rects
my $title_text = “Text”; # test-output
my $background = SDL::Surface->new(-name => “level_editor.png”);
my $surface_dialog = SDL::Surface->new(-name => “void_panel.png”);
$rect{dialog} = SDL::Rect->new(
-x => 0,
’-y’ => 0,
-width => $surface_dialog->width,
-height => $surface_dialog->height,
);
$rect{middle} = get_dialog_rect();
$surface_dialog->blit($rect{dialog}, $app, $rect{middle});
$app->print(
$rect{middle}->x + $rect{middle}->width/2 - 12 * length($title_text)/2,
$rect{middle}->y + 5, uc($title_text)
);
############################################################
Aktionen definieren
############################################################
my %actions = (
SDL_QUIT() => sub { exit(0); },
SDL_KEYDOWN() => &keydown,
);
############################################################
MainLoop
############################################################
$app->loop(%actions);
############################################################
SUBS
############################################################
sub keydown {
# subroutine to get the rect where the promt will go
my $t = “Text”;
my $dialog = get_dialog_rect();
$app->print(
$dialog->x + $dialog->width/2 - 12 * length($t)/2,
$dialog->y + 5,
$t,
);
} # /keydown
sub get_dialog_rect {
SDL::Rect->new(
-x => 320 - $surface_dialog->width/2,
’-y’ => 320 - $surface_dialog->height/2,
-width => $surface_dialog->width, -height => $surface_dialog->height,
);
}
The error-output is: “Fatal signal: Segmentation Fault (SDL Parachute
Deployed)”
Any ideas / examples (no need using perl)?
mfg Alex