Alien-CSFML
view release on metacpan or search on metacpan
examples/csfml.pl view on Meta::CPAN
sprite = sfSprite_create();
sfSprite_setTexture(sprite, texture, sfTrue);
/* Create a graphical text to display */
// https://github.com/googlefonts/roboto/releases
font = sfFont_createFromFile("Roboto-Regular.ttf");
if (!font)
return -1;
text = sfText_create();
sfText_setString(text, "Hello SFML");
sfText_setFont(text, font);
sfText_setCharacterSize(text, 50);
/* Load a music to play */
// https://en.wikipedia.org/wiki/File:Binbeat_sample.ogg
music = sfMusic_createFromFile("Binbeat_sample.ogg");
if (!music)
return -1;
/* Play the music */
sfMusic_play(music);
/* Start the game loop */
while (sfRenderWindow_isOpen(window))
{
/* Process events */
while (sfRenderWindow_pollEvent(window, &event))
{
/* Close window : exit */
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
/* Clear the screen */
sfRenderWindow_clear(window, sfBlack);
/* Draw the sprite */
sfRenderWindow_drawSprite(window, sprite, NULL);
/* Draw the text */
sfRenderWindow_drawText(window, text, NULL);
/* Update the window */
sfRenderWindow_display(window);
}
/* Cleanup resources */
sfMusic_destroy(music);
sfText_destroy(text);
sfFont_destroy(font);
sfSprite_destroy(sprite);
sfTexture_destroy(texture);
sfRenderWindow_destroy(window);
return 0;
}
END
my $OBJ = $CC->compile( source => $SRC, include_dirs => [ $SF->include_dirs ] );
my $EXE = $CC->link_executable(
objects => $OBJ,
extra_linker_flags => $SF->ldflags(qw[graphics system window audio])
);
print system(
(
$^O eq 'MSWin32' ? '' :
'LD_LIBRARY_PATH=' . join( ':', '.', $SF->library_path() ) . ' '
) .
'./' . $EXE
) ? 'Aww...' : 'Yay!';
END { unlink grep defined, $SRC, $OBJ, $EXE; }
}
( run in 1.711 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )