Writing Games with SDL Perl

2014-06-09 Thread Alexander Becker


Hi all!



I just wondered why the article Writing Games with SDL Perl isnt part of the SDLPerl website.

There is a web site called sdl.perl.org and his has a lot of (outdated) stuff on SDL and Perl.

But when it comes to content interesting for beginners, all we get is a link to a repo on github where you see the HTML source code of the text(a link to the HTML source code of a web site makes me cry) or a link to a PDF file that ypu have to download before you can open it.

As its already available as HTML, why exactly arent we showing it as a web site on sdl.perl.org?



Please correct me if Im wrong, but arent we interested in new people starting to use SDLPerl? How should one even get started if we put such obstacles in his way?

Having outdated and partial manpages online isnt a good thing, but why additionally hide the good things?



So, enough of the rant. How can I help? What about the following: just put the page online, as first item under Articles.

Lets make it the first item even if its not the most recent one. E.g. something called sticky. Maybe make a bubble to it like Get started here. Something glassy like that: http://www.clker.com/cliparts/Q/g/q/4/q/4/45-red-star-price-tag-md.png

Is there a way to contribute?



Regards,

Alex




Problem viewing bug list via CPAN RT

2012-04-30 Thread Alexander Becker
Hi there!

If you go to this page on CPAN:
http://search.cpan.org/~froggs/Alien-SDL-1.430/, you cannot access the
View/Report Bugs link. 
The target (http://search.cpan.org/~froggs/Alien-SDL-1.430/) returns an
error (cannot connect to server).

This should probably redirect to the github page, shouldn't it?

HTH,
Alex



Re: Revamping SDL_Manual

2012-01-09 Thread Alexander Becker
Hi Kartik,

I recently started working with the SDL Manual, but I don't have a game in 
mind. Regardless of that, I find it very useful to see the things you can do 
with SDL demonstrated with games. What I'm missing so far, and what is part of 
every game, too, is UI stuff. How do buttons work with SDL, how do you change 
the state of a button element (normal, active, hover, diabled,  etc.) and how 
do you encapsulate such UI elements properly.

Basically, I'm still experimenting to find a way to create a good button class 
for a menu. I know there is a package out there that provides methods for 
drawing menus, but especially when writing your own games / apps, I guess one 
might want to implement its own kind of menu with nifty nice effects, layout 
and so on.

So this is my idea: add a chapter on UI elements (not only buttons, but 
(high-score-tables, text fields etc.). Unfortunately, all I can add to this 
project so far (I'm still a SDL n00b) are possibly dumb questions. For example, 
I don't know how to adjust a text on a surface for a button. By adjusting, I 
mean something like aligning to the left or the right or automatically 
splitting the text up an breaking into a new line when a given with would be 
exceeded (I'm generating buttons with unknown text length, which is quite 
problematic).

hth, 
Alex

 Original-Nachricht 
 Datum: Mon, 9 Jan 2012 16:34:25 -0500
 Von: Kartik Thakore thakore.kar...@gmail.com
 An: sdl-devel@perl.org, chromatic chroma...@wgz.org
 Betreff: Revamping SDL_Manual

 Hello guys,
 
 So as I have gotten busy over the last couple months with my startup and
 masters the  SDL Manual has fell behind, and I would like to ask if anyone
 is interested in taking on writing new chapters or reorganizing SDL
 Manual.
 We can discuss any new chapters to add and work with reorganize it. An
 idea
 I have is to change the name to Perl Game Development and incorporate more
 then just SDL chapters into the manual. Any suggestions are welcome!
 
 Regards,
 Kartik

-- 
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!   
Jetzt informieren: http://www.gmx.net/de/go/freephone


AW: How to play an mp3 file from a database

2011-12-03 Thread Alexander Becker
Wohoo! That’s really great! Here is my current (OMG: it’s SDL + Tk)
proof-of-concept-script.

It plays a file via start and stop buttons. In case anyone has suggestions,
please don’t hesitate to drop me an email.

 

[code]

#!perl

 

use strict;

use warnings;

use utf8;

use Tk;

use DBI;

use SQL::Abstract::Limit;

use SDL;

use SDL::Audio;

use SDL::Mixer;

use SDL::Mixer::Samples;

use SDL::Mixer::Channels;

use SDL::Mixer::Music;

use SDL::RWOps;

SDL::init(SDL_INIT_AUDIO);

SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );

 

my $mw = tkinit();

 

unless( SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) == 0 ) {

Carp::croak Cannot open audio: .SDL::get_error(); 

}

 

$mw-Button(

-text = 'play',

-command = sub{

   my $buffer = get_audio_buffer();

   my $rwops = SDL::RWOps-new_const_mem(
$buffer );

   my $background_music =
SDL::Mixer::Music::load_MUS_RW( $rwops );

   

   unless( $background_music ) {

   Carp::croak Cannot load
music file [buffer from DB]:  . SDL::get_error();

   }



   SDL::Mixer::Music::play_music(
$background_music, 20 );

},

)-pack();

 

$mw-Button(

-text = 'stop',

-command = sub{

   SDL::Mixer::Music::halt_music();

},

)-pack();

 

$mw-MainLoop();

 

 

 

sub get_audio_buffer {

my $sql = SQL::Abstract::Limit-new( limit_dialect = 'LimitXY' );;



my $table = 'words';

my @fields = (qw/audio/);

my %where = (

id = 2,

);

my @order = ();

my $limit = 1;

my $offset = 0;

my ( $stmt, @bind ) = $sql-select( $table, \@fields, \%where, \@order,
$limit, $offset );

my $database = 'test';

my $db_host = '127.0.0.1';

my $db_port = '3306';

my $dsn = DBI:mysql:database=$database;host=$db_host;port=$db_port;

my $username = 'test';

my $password = 'test';

my $dbh = DBI-connect($dsn, $username, $password) or die('Cannot
connect to DB: ' . DBI-errstr());

my $sth = $dbh-prepare( $stmt );

$sth-execute( @bind );



my ($buffer) = $sth-fetchrow_array();



return $buffer;

} # /get_audio_buffer

[/code]

 

Here is the output of “perl Build.PL”. There is an error for : execinfo.h,
however, build, build test and build install runs fine.

 

[snip]

C:\zwischen\cpan\PerlGameDev-SDL-44c341fperl Build.PL

*** !!!WARNING!!! 

This Release breaks back compatibility support with versions 2.4x and below

**

Using 'My::Builder::Windows' class ...

Detecting available libraries ...

[Alien::SDL] Testing header(s): SDL.h

[Alien::SDL] Testing header(s): SDL_mixer.h

[Alien::SDL] Testing header(s): SDL_imageFilter.h

[Alien::SDL] Testing header(s): SDL_image.h

[Alien::SDL] Testing header(s): SDL_ttf.h

[Alien::SDL] Testing header(s): SDL_framerate.h

[Alien::SDL] Testing header(s): SDL_gfxBlitFunc.h

[Alien::SDL] Testing header(s): SDL_gfxPrimitives.h

[Alien::SDL] Testing header(s): SDL_rotozoom.h

[Alien::SDL] Testing header(s): SDL_Pango.h

Writing config_data ...

Saving some info to 'notes' ...

[Alien::SDL] Testing header(s): execinfo.h, signal.h NOK: (error:
execinfo.h: No

such file or directory)

Can't find dist packages without a MANIFEST file

Run 'Build manifest' to generate one

 

WARNING: Possible missing or corrupt 'MANIFEST' file.

Nothing to enter for 'provides' field in metafile.

Created MYMETA.yml and MYMETA.json

Creating new 'Build' script for 'SDL' version '2.535_01'

 

C:\zwischen\cpan\PerlGameDev-SDL-44c341f

[/snip]

 

Will this be in an official release of SDL? Because this would be a really
nice feature, that could be advertised, e.g. via blogs entries etc.. I could
write a german one.

 

Best regards  thanks a lot,

Alex

 

Von: Tobias Leich [mailto:em...@froggs.de] 
Gesendet: Donnerstag, 1. Dezember 2011 18:37
An: Alexander Becker
Betreff: Re: How to play an mp3 file from a database

 

Hi Alex,

You can checkout the c-sdl-rwops branch at github or download the zipfile if
you are not experienced with git by using this link:

https://github.com/PerlGameDev/SDL/zipball/c-sdl-rwops

Usage:

 my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );

load_MUS_RW does the same like load_MUS except that it accepts an SDL::RWOps
http://search.cpan.org/perldoc?SDL%3A%3ARWOps -object rather than a
filename.

Example for loading music from a variable:

 use SDL;
 use SDL::Mixer;
 use SDL::Mixer::Music;
 use SDL::RWOps;
 
 [...]
 
 my $rwops = SDL::RWOps-new_const_mem( $scalar_holding_music );
 my $music = SDL::Mixer::Music::load_MUS( $rwops

AW: How to play an mp3 file from a database

2011-11-30 Thread Alexander Becker
Hi breno,

thank you for the quick response. It helped.
I had a look into mixer_samples.t and line 106 states, that quick_load_WAV
is not (yet? Who do I have to bribe with what to get it?) implemented.

Here is a working piece of code using temporary files. Of course, you need a
database containing audio files. 

Best regards,
Alex

[code]
#!perl

use strict;
use warnings;
use utf8;
use DBI;
use SQL::Abstract::Limit;
use File::Temp;
use SDL;
use SDL::Audio;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
SDL::init(SDL_INIT_AUDIO);
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );

unless( SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) == 0 ) {
Carp::croak Cannot open audio: .SDL::get_error(); 
}

my $buffer = get_audio_buffer();

# -- write audio buffer to temp file
my $fh = File::Temp-new( UNLINK = 1, SUFFIX = '.mp3' );
$fh-unlink_on_destroy( 1 );
print $fh $buffer;
my $fname = $fh-filename;

# close the handle or the temfile will have some sort of lock on it and
cannot be read
$fh-close();

my $background_music = SDL::Mixer::Music::load_MUS( $fname );

unless( $background_music ) {
Carp::croak Cannot load music file [buffer from DB]:  .
SDL::get_error();
}

SDL::Mixer::Music::play_music( $background_music,0 );

sleep(6);

SDL::Mixer::Music::halt_music();
SDL::Mixer::close_audio;
exit(0);



sub get_audio_buffer {
my $sql = SQL::Abstract::Limit-new( limit_dialect = 'LimitXY' );;

my $table = 'audio_files';
my @fields = (qw/audio/);
my %where = (
id = 2,
);
my @order = ();
my $limit = 1;
my $offset = 0;
my ( $stmt, @bind ) = $sql-select( $table, \@fields, \%where, \@order,
$limit, $offset );
my $database = 'database_name';
my $db_host = 'your_host';
my $db_port = '3306';
my $dsn = DBI:mysql:database=$database;host=$db_host;port=$db_port;
my $username = 'username';
my $password = 'password';
my $dbh = DBI-connect($dsn, $username, $password) or die('Cannot
connect to DB: ' . DBI-errstr());
my $sth = $dbh-prepare( $stmt );
$sth-execute( @bind );

my ($buffer) = $sth-fetchrow_array();

return $buffer;
} # /get_audio_buffer
[/code]

-Ursprüngliche Nachricht-
Von: breno [mailto:oainikus...@gmail.com] 
Gesendet: Dienstag, 29. November 2011 06:34
An: Alexander Becker
Cc: sdl-devel@perl.org
Betreff: Re: How to play an mp3 file from a database

On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker   wrote:
 Dear all!


Hi there!

 I just tried the example code of the SDL Manual where you play some music.
 By the SDL manual, I refer to the one that is hidden at the bottom of 
 the sdl.perl.org page, so that you really have to search for it in 
 order to find it - and even then you have to get along with an ugly github
interface.


There's a new project website under way, but we're missing people to work in
it. Please join #sdl in irc.perl.org if you want to help us get it right :)

 So, in general: Is there a way to play mp3 files?

Yup.

If your libsdl was compiled with mp3 support, all you have to do
(iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags
when you call SDL::Mixer::init():

  SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );

then use load_MUS() and play_music() from SDL::Mixer::Music to play
mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to
play mp3 effects (yes, the function is named load_WAV() but plays different
formats too if they're available).

The documentation in SDL::Mixer, SDL::Mixer::Music and SDL::Mixer::Samples
should be helpful, as some of the test files (t/mixer_music.t comes to
mind).

 And in particular: is there a way to play mp3 files that are in a
variable?
 Or do I have to work with temporary files?


Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the right
thing. You'll have to test it though.

Cheers,

breno
-
eMail ist virenfrei.
Von AVG überprüft - www.avg.de
Version: 10.0.1411 / Virendatenbank: 2092/4046 - Ausgabedatum: 29.11.2011 



How to play an mp3 file from a database

2011-11-28 Thread Alexander Becker
Dear all!

I just tried the example code of the SDL Manual where you play some music.
By the SDL manual, I refer to the one that is hidden at the bottom of the
sdl.perl.org page, so that you really have to search for it in order to find
it - and even then you have to get along with an ugly github interface. 

The good news is, that it worked perfectly here on Win 7 x64. Thank you!
The bad news is, that I don't have ogg or wav files, but mp3 files. And I
have them in a database (please don't ask why and please don't propose to
store them as files).

So, in general: Is there a way to play mp3 files? 
And in particular: is there a way to play mp3 files that are in a variable?
Or do I have to work with temporary files?

Here is what I got so far:

[code]
#!perl

use strict;
use warnings;
use SDL;
use Carp;
use SDL::Audio;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
SDL::init(SDL_INIT_AUDIO);

unless( SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) == 0 )
{
Carp::croak Cannot open audio: .SDL::get_error(); 
}

my $sound_file = 'data/ghostngoblins.mp3';
my $sample = SDL::Mixer::Samples::load_MUS($sound_file);

unless( $sample)
{
Carp::croak Cannot load file [$sound_file]: .SDL::get_error(); 
}

my $playing_channel = SDL::Mixer::Channels::play_channel( -1, $sample, 0 );

sleep(60);

SDL::Mixer::Music::halt_music();
SDL::Mixer::close_audio;
exit(0);
[/code]

However, this code dies with an error: Use of inherited AUTOLOAD for
non-method SDL::Mixer::Samples::load_MUS() is deprecated at
yadayada\play_sdl.pl line 20..
The above code works fine when using an ogg file (using load_MUS()) or an
wav file (load_WAV()).

Please help :)

Best regards,
Alex