Printing out a text

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

Ummm, not sure of SDL_ttf has been ported over to perl but that’s one
way to do it. There is another way, which is to blit prerendered text
onto your surfaces thus creating semi-magical words on your
applications screen surface.

If you need some point of reference, search for “BFont” or "SFont"
they are by far the most part the most popular addon libraries for
rendering bitmap text.

Happy hacking!

Hello!

Now, I used the Font and SFont-methods to load a font (taken from frozen
bubble) and display it by putting it on a rect and blitting this to
another.
But I don’t see anything else than the surface!?
Because the documentation is very rare and restricted respectively, I
don’t know if I need any more commands to write to a surface.

Perhabs, you may send me a c++ - example-code?

My Code:#---------------------------------------------------------------------#
#!/Perl/bin/perl

use strict;
use warnings;
use Data::Dumper;
use FindBin qw($Bin);
use SDL;
use SDL::App;
use SDL::Rect;
use SDL::Color;
use SDL::Surface;
use SDL::Tool::Font;
use SDL::TTFont;
use vars qw(%rect %rects %apprects);

############################################################

Definieren der Elemente des Programms

############################################################

my @t = qw(T e x t);

my $app = SDL::App->new(
-title => ‘Animation’,
-width => 640,
-height => 480,
-depth => 32,
);

my $color = SDL::Color->new(
-r => 0xff,
-g => 0xff,
-b => 0xff,
);

my $frame_rect = SDL::Rect->new(
-height => 200,
-width => 200,
-x => 0,
-y => 0,
);

my $dest_rect = SDL::Rect->new(
-height => 200,
-width => 200,
-x => 0,
’-y’ => 0,
);

$app->fill($frame_rect, $color);

my $font = getFont("$Bin/grafik/font-hi.png");
$font->use();
SDL::SFont::PutString( $frame_rect, 5, 5, join(’’, at t));

$app->blit( $frame_rect, $app, $dest_rect );
$app->update( $dest_rect );

############################################################

Actions 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
} # /keydown

sub getFont {
my $font = shift;
die “Die Schrift “$font” wurde nicht gefunden” unless -e $font;
return SDL::Font->new($font);
}
#---------------------------------------------------------------------#

mfg Alex

Am Fri, 1 Apr 2005 09:48:37 -0800 schrieb Jack Doe :

Ummm, not sure of SDL_ttf has been ported over to perl but that’s one
way to do it. There is another way, which is to blit prerendered text
onto your surfaces thus creating semi-magical words on your
applications screen surface.

If you need some point of reference, search for “BFont” or "SFont"
they are by far the most part the most popular addon libraries for
rendering bitmap text.

Happy hacking!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl