Hi, here is an easy to use (with PIR code) wrapper of the SDL library. It tries to hide all internals of the wrapper and makes the most important SDL functions directly available in PIR code.
jens
=head1 TITLE library/sdl.imc - PIR interface to SDL =head1 SYNOPSIS .include "library/sdl.imc" # _main is the entry point of SDL apps .sub _main .local pmc screen .local pmc events # init SDL _SDL_Init( SDL_INIT_VIDEO ) # set the videomode screen = _SDL_SetVideoMode( 320, 420, 0, SDL_SWSURFACE ) # .. create your own event entries ... events = _create_events() # start the event loop _SDL_loop( events ) # shut SDL down _SDL_Quit() .pcc_begin_return .return 0 .pcc_end_return .end =head1 DESCRIPTION This wrapper provides access to the SDL library. Please also refer to the SDL documentation for more information about the functions presented here. =head1 FUNCTIONS This library provides the following functions: =over 4 =cut # this is where the execution starts .sub _init_crt _init() # call the SDL main function _main() end .end .include "library/sdl_types.imc" .include "library/sdl_constants.imc" .include "library/sdl_image.imc" .include "library/dumper.imc" .sub _init .include "library/sdl.pasm" _init_SDL_Image() .pcc_begin_return .pcc_end_return .end .const int SDL_INIT_TIMER = 0x00000001 .const int SDL_INIT_AUDIO = 0x00000010 .const int SDL_INIT_VIDEO = 0x00000020 .const int SDL_INIT_CDROM = 0x00000100 .const int SDL_INIT_JOYSTICK = 0x00000200 # Don't catch fatal signals .const int SDL_INIT_NOPARACHUTE = 0x00100000 # Not supported on all OS's .const int SDL_INIT_EVENTTHREAD = 0x01000000 .const int SDL_INIT_EVERYTHING = 0x0000FFFF =item _SDL_Init( flags ) Initializes the SDL library. =over 4 =item flags you can XOR one or more of the following constants to initialize the specific SDL subsystems: SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_INIT_CDROM, SDL_INIT_JOYSTICK, SDL_INIT_NOPARACHUTE, SDL_INIT_EVENTTHREAD, SDL_INIT_EVERYTHING =back Please refer to the SDL documentation for more information about the meanings of the flags. =cut .sub _SDL_Init .param int mask .local pmc nci pushp nci nci = global "SDL::Init" .pcc_begin prototyped .arg mask .nci_call nci .result mask .pcc_end popp nci .pcc_begin_return .return mask .pcc_end_return .end .const int SDL_SWSURFACE = 0x00000000 .const int SDL_HWSURFACE = 0x00000001 .const int SDL_ASYNCBLIT = 0x00000004 # Available for SDL_SetVideoMode() .const int SDL_ANYFORMAT = 0x10000000 .const int SDL_HWPALETTE = 0x20000000 .const int SDL_DOUBLEBUF = 0x40000000 .const int SDL_FULLSCREEN = 0x80000000 .const int SDL_OPENGL = 0x00000002 .const int SDL_OPENGLBLIT = 0x0000000A .const int SDL_RESIZABLE = 0x00000010 .const int SDL_NOFRAME = 0x00000020 # Used internally (read-only) .const int SDL_HWACCEL = 0x00000100 .const int SDL_SRCCOLORKEY = 0x00001000 .const int SDL_RLEACCELOK = 0x00002000 .const int SDL_RLEACCEL = 0x00004000 .const int SDL_SRCALPHA = 0x00010000 .const int SDL_PREALLOC = 0x01000000 =item _SDL_SetVideMode( width, height, bpp, flags ) Sets the video mode. You can specifiy a bpp of 0, which will use your desktop's current bit depth. The most commonly used flags are: =over 4 =item SDL_SWSURFACE Surface is in system memory =item SDL_HWSURFACE Surface is in video memory =item SDL_ASYNCBLIT Use asynchronous blits if possible =item SDL_ANYFORMAT Allow any video depth/pixel-format =item SDL_DOUBLEBUF Set up double-buffered video mode =item SDL_FULLSCREEN Surface is a full screen display =back =cut .sub _SDL_SetVideoMode .param int width .param int height .param int bpp .param int flags .local pmc screen_settings .local object screen new screen_settings, .PerlHash set screen_settings['width'], width set screen_settings['height'], height set screen_settings['bpp'], bpp set screen_settings['flags'], flags screen = _new_SDL_Screen( screen_settings ) global "MP_screen" = screen .pcc_begin_return .return screen .pcc_end_return .end =item _SDL_UpdateRect( screen, x, y, w, h ) Update the specified screen region. =cut .sub _SDL_UpdateRect .param pmc screen .param int x .param int y .param int w .param int h .local pmc nci .local pmc rect .local int ret pushp nci pushp rect nci = global "SDL::UpdateRect" new rect, .PerlHash set rect["x"], x set rect["y"], y set rect["w"], w set rect["h"], h .pcc_begin prototyped .arg screen .arg rect .nci_call nci .result ret .pcc_end popp rect popp nci .pcc_begin_return .return ret .pcc_end_return .end =item _SDL_FillRect( surface, rect, color ) Fill the specified region on the specified surface with the specified color. =cut .sub _SDL_FillRect .param pmc surface .param pmc rect .param int color .local pmc nci saveall nci = global "SDL::FillRect" .pcc_begin prototyped .arg surface .arg rect .arg color .nci_call nci .pcc_end restoreall .pcc_begin_return .pcc_end_return .end =item rect = _SDL_Rect( x, y, w, h ) Create an SDL_Rect struct and init it with the specified members. =cut .sub _SDL_Rect .param int x .param int y .param int w .param int h .local pmc ret ret = _new_SDL_Rect() set ret["width"], w set ret["height"], h set ret["x"], x set ret["y"], y .pcc_begin_return .return ret .pcc_end_return .end .sub _SDL_Quit .local pmc nci saveall nci = global "SDL::Quit" .pcc_begin prototyped .nci_call nci .pcc_end restoreall .pcc_begin_return .pcc_end_return .end =head1 AUTHOR Written and maintained by chromatic, E<lt>chromatic at wgz dot orgE<gt>, with help from Jens Rieks. Please send patches and suggestions to the Perl 6 Internals mailing list. =head1 COPYRIGHT Copyright (c) 2004, The Perl Foundation. =cut