Guile-SDL


Next: , Up: (dir)

The (sdl *) Modules


Next: , Previous: Top, Up: Top

1 Introduction

The (sdl *) modules are an interface to the SDL (Simple Direct Media Layer) library. The goal is to provide both a clean and direct interface to the lowest level SDL, while extending with higher level concepts where useful, such as default arguments and functional-style application of graphics routines. Several SDL add-on libraries have been wrapped and included with Guile-SDL, including SDL_image (for loading multiple image formats), SDL_ttf (for rendering true type fonts), SDL_mixer (for playing/mixing different audio formats), and SDL_rotozoom (for rotating and scaling images). In addition, some low-level 2D graphics primitives have been provided.


Next: , Up: Introduction

1.1 Quick Start

To whet your appetite, and hopefully get you excited about the ease and flexibility of programming with Guile-SDL, we begin with a simple example. The following program is a simple image browser. You can cycle through images by using space, n or right to go forward, backspace, p or left to go backwards, and escape or q to quit.

     ;; load the SDL module and some useful srfi's
     (use-modules ((sdl sdl) #:renamer (symbol-prefix-proc 'SDL:))
                  (srfi srfi-1)
                  (srfi srfi-2))
     
     ;; initialize the video subsystem
     (SDL:init '(SDL_INIT_VIDEO))
     
     ;; directory to search for images in
     (define image-dir "/usr/share/pixmaps/")
     
     ;; utility to test if a path is a directory
     (define (file? f)
       (let* ((stats (stat f))
              (type (stat:type stats)))
         (eq? type 'regular)))
     
     ;; build a ring of image file names
     (define image-ring
       (let ((dir (opendir image-dir)))
         (letrec ((D (lambda (ls)
                       (let ((file (readdir dir)))
                         (if (eof-object? file)
                             (begin (closedir dir) ls)
                             (D (cons (string-append image-dir file)
                                      ls)))))))
           (apply circular-list (reverse (filter file? (D '())))))))
     
     ;; functions to cycle through the ring
     (define (next-image)
       (let ((next (car image-ring)))
         (set! image-ring (cdr image-ring))
         next))
     
     (define (prev-image)
       (let ((orig image-ring))
         (while (not (eq? (cddr image-ring) orig))
           (set! image-ring (cdr image-ring)))
         (let ((image (car image-ring)))
           (set! image-ring (cdr image-ring))
           image)))
     
     ;; display an image given a filename
     (define (show file)
       (and-let* ((image (SDL:load-image file)))
         (SDL:set-video-mode (SDL:surface:w image) (SDL:surface:h image) 24)
         (SDL:blit-surface image)
         (SDL:flip)))
     
     ;; show the first image
     (show (next-image))
     
     ;; event handler
     (let handle ((e (SDL:make-event)))
       (if (SDL:wait-event e)
         (case (SDL:event:type e)
           ((SDL_KEYDOWN)
            (case (SDL:event:key:keysym:sym e)
              ((SDLK_LEFT SDLK_BACKSPACE)
               (show (prev-image)))
              ((SDLK_RIGHT SDLK_SPACE)
               (show (next-image)))
              ((SDLK_ESCAPE SDLK_q)
               (SDL:quit)
               (quit))))))
       (handle e))


Next: , Previous: Quick Start, Up: Introduction

1.2 Naming Conventions

The most important thing to learning a wrapped library for a programming language, assuming you know the language and the library, is to know the naming conventions. Then you can begin programming without having to look up the exact function reference (available in the rest of this document).


Next: , Up: Naming Conventions

1.2.1 Renaming C Functions

As with standard guile naming conventions, all names are converted to lower-case, and underscores are replaced with hyphens. Functions that modify one or more arguments have an exclamation point (!) appended, and functions which ask a question and return a boolean value have a question mark (?) appended.


Next: , Previous: Renaming C Functions, Up: Naming Conventions

1.2.2 Enums and Constants

SDL enumerated types and constants are passed and returned as symbols, thus enforcing their "constant" nature and for ease of use in case statements. Flags, such as the SDL initialization flags and video surface flags, are treated as lists of symbols, each constant in the flag group that you would or together in C code becoming a symbol in the list. All such constant symbols retain their exact C names.

A particular set of enums is called an enumstash. Likewise flagstash for flags.

— enumstash: fading-status

Returned by fading-music and fading-channel. See Audio. Values are MIX_foo, where foo can be:

          FADING{IN,OUT}
          NO_FADING
— enumstash: event-types

First arg to make-event and to event-state. See Events. Values are SDL_foo, where foo can be:

          ACTIVEEVENT
          JOY{AXIS,BALL,HAT}MOTION
          JOYBUTTON{DOWN,UP}
          KEY{DOWN,UP}
          MOUSEBUTTON{DOWN,UP}
          MOUSEMOTION
          QUIT
          SYSWMEVENT
          USEREVENT
          VIDEORESIZE
— enumstash: event-keys

First arg to make-keysym. See Events. Values are SDLK_foo, where foo can be:

          a b c d e f g h i j k l m n o p q r s t u v w x y z
          0 1 2 3 4 5 6 7 8 9
          
          AMPERSAND   BACKQUOTE   CAPSLOCK   DELETE   END
          ASTERISK    BACKSLASH   CARET      DOLLAR   EQUALS
          AT          BACKSPACE   CLEAR               ESCAPE
                      BREAK       COLON               EURO
                                  COMMA               EXCLAIM
          
          F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15
          
          HASH   INSERT
          HELP
          HOME
          
          KP0 KP1 KP2 KP3 KP4 KP5 KP6 KP7 KP8 KP9
          
          KP_DIVIDE
          KP_ENTER
          KP_EQUALS
          KP_MINUS
          KP_MULTIPLY
          KP_PERIOD
          KP_PLUS
          
          LEFT  RIGHT  UP  DOWN
          
          LALT    RALT
          LCTRL   RCTRL
          LMETA   RMETA
          LSHIFT  RSHIFT
          LSUPER  RSUPER
          
          LEFTBRACKET  RIGHTBRACKET
          LEFTPAREN    RIGHTPAREN
          
          LESS  GREATER
          
          MENU      PAGEDOWN   QUESTION   SCROLLOCK
          MINUS     PAGEUP     QUOTE      SEMICOLON
          MODE      PAUSE      QUOTEDBL   SLASH
                    PERIOD                SPACE  TAB
          NUMLOCK   PLUS       RETURN     SYSREQ
                    POWER
                    PRINT                 UNDERSCORE
— enumstash: event-states

Second arg to and return value of event-state. See Events. Values are:

          SDL_ENABLE
          SDL_IGNORE
          SDL_QUERY
— enumstash: alpha-enums

Third arg to set-alpha!. See Video. Values are:

          SDL_ALPHA_TRANSPARENT
          SDL_ALPHA_OPAQUE
— enumstash: gl-enums

Currently unused.

You can use enumstash-enums and flagstash-flags to examine the enums and flags encapsulated by these respectively typed objects. You may also use integers where enums/flags are expected, and can convert between the symbol and numeric value with enum->number, number->enum, flags->number and number->flags.

— Procedure: enumstash-enums enumstash_type

Return the list of symbols associated with enum-type.

— Procedure: enum->number enumstash_type symbol

Convert an enum number or symbol to a number.

— Procedure: number->enum enumstash_type number

Convert a number to an enum.

— Procedure: flagstash-flags stash

Return a list of all the flags (symbols) in stash, a flagstash object, in unspecified order.

— Procedure: flags->number stash flags

Use stash to convert flags to a number. flags is a list of symbols.

— Procedure: number->flags stash number

Use stash to convert number to a list of symbols.


Previous: Enums and Constants, Up: Naming Conventions

1.2.3 Create and Make

The standard SDL prefix for creating a new instance of a type is create. The standard Guile prefix is make. Wherever an SDL function uses the create prefix we will keep it. Object creation functions unique to Guile, such as make-rect, will use make as a prefix. In addition, we will sometimes introduce higher-level creation functions, such as make-surface, which is a wrapper to create-rgb-surface which provides useful default values from the current screen information.


Next: , Previous: Naming Conventions, Up: Introduction

1.3 Limitations

There are some known problems with Guile-SDL modules. This section attempts to make them well-known, if not well-liked...


Previous: Limitations, Up: Introduction

1.4 TODO

Here is an excerpt of the TODO file:

- 0.3 "coverage"
  - (sdl gfx)
    + SDLgfxBlitRGBA
    + SDLgfxSetAlpha
    - SDLimageFilter* (many funcs)
      + with C fallback
      - assembler only
  - interface present but "not yet implemented"
    + peep-event
    - set-event-filter
    - get-event-filter
    + event-state
    + get-key-state
    + scale-surface (deleted)
  - programming practice review
    - return values
      - smob safety
      - 0-means-success
      - consistency
    - use unsigned long for colors
  - /usr/include/SDL/*.h coverage
    - mixer
      - hooks
      - effects
      + panning / position / distance
  - opengl?

- 0.4 "control"
  - threading system
  - signals
  - interop w/ other event loops?
    - fastevents

- 0.5 "glitches"
  - review/revise interfaces (WARNING: disruptive)
  - error handling cleanup
    - document policy
    - cases: NULL, -1, ...

- 0.6 "earth"
  - handle pre-installed libSDLgfx
    - write configure check for it
    - use it if it is featureful enough
  - two-level modularization
    - many small modules: (sdl modules cdrom)
    + overarching: (sdl sdl)
  - finalize interfaces

- 0.7 "water"
  - write configure check for guile that can load binary modules
  - executable modules: (sdl scripts FOO)
  - third-party post-install extension framework

- 0.8 "fire"
  - performance tweaking
  - user-alloc alternatives (less consing) for event procs

- 0.9 "air"
  - you/

- 1.0

- eventually
  - port to Mac OSX/BeOS (ignore windoze)
  - switch to an automated wrapper generater


Basically, a 1.0 release is still quite far away. But we'll get there at some point. Another interesting thing to consider is, what happens if there is another release of SDL after 1.2? What if it is (gasp) incompatible with SDL 1.2?


Next: , Previous: Introduction, Up: Top

2 General SDL

— Procedure: flagstash:init

Return the flagstash object for init flags. See Enums and Constants.

     SDL_INIT_foo, where foo can be:
     VIDEO            CDROM            JOYSTICK
     EVERYTHING       EVENTTHREAD      AUDIO
     NOPARACHUTE
— Procedure: init sel

Initialize SDL based on configuration flags sel. sel is a list of symbols whose names all begin with SDL_INIT_.

— Procedure: init-subsystem sel

Initialize the SDL subsystems represented by sel. sel is a list of flags (symbols) from the same set useful for init.

— Procedure: quit

Shut down all SDL subsystems. Return #t.

— Procedure: quit-subsystem sel

Shut down the SDL subsystems represented by sel. sel is a list of flags (symbols) from the same set useful for init. Return #t.

— Procedure: was-init sel

Check if the SDL subsystems represented by sel have been initialized. sel is a list of flags (symbols) from the same set useful for init. Return a list likewise composed.

— Procedure: get-ticks

Return the number of milliseconds since the SDL library initialization.

— Procedure: delay ms

Wait ms milliseconds. The return value is unspecified.

— Procedure: get-error

Return the current SDL error string.


Next: , Previous: General SDL, Up: Top

3 Video

— Procedure: flagstash:video

Return the flagstash object for video flags. See Enums and Constants.

     SDL_foo, where foo can be:
     OPENGL       SRCALPHA     ASYNCBLIT
     OPENGLBLIT   NOFRAME      RLEACCEL
     HWPALETTE    RLEACCELOK   SRCCOLORKEY
     HWACCEL      PREALLOC     SWSURFACE
     HWSURFACE    ANYFORMAT    FULLSCREEN
     RESIZABLE    DOUBLEBUF
— Procedure: flagstash:palette

Return the flagstash object for palette flags. See Enums and Constants.

     SDL_LOGPAL       SDL_PHYSPAL
— Procedure: flagstash:overlay

Return the flagstash object for overlay flags. (Actually, these are "common overlay formats", not flags.) See Enums and Constants.

     SDL_foo_OVERLAY, where foo can be:
       YVYU  YUY2  IYUV  YV12  UYVY
— Procedure: create-cursor data mask w h x y

Return a new cursor from data and mask (vectors), sized w by h and with hot pixel located at x,y.

— Procedure: create-yuv-overlay width height format [display]

Create a new YUV overlay, sized width by height with overlay format (a symbol or an exact number). Optional arg display specifies a surface to use instead of creating a new one.

— Procedure: get-video-surface

Return the current display surface.

— Procedure: get-video-info

Return information about the video hardware as an alist. Keys are: hw-available, wm-available, bit-hw, blit-hw-CC, blit-hw-A, blit-sw, blit-sw-CC, blit-sw-A, blit-fill, video-mem and vfmt.

— Procedure: video-driver-name

Return the name of the video driver.

— Procedure: list-modes [format [flags]]

Return a list of available screen dimensions for pixel format and flags. Format defaults to that for the current screen. Flags default to none (see flagstash:video). Return #f if no modes are available, #t if all are available.

— Procedure: video-mode-ok width height bpp [flags]

Check to see if a particular video mode is supported. Args are width, height, bpp (numbers), and flags (see flagstash:video). Return #f if the mode is not supported, or a number indicating the bits-per-pixel of the closest available mode supporting width and height.

— Procedure: set-video-mode width height bpp [flags]

Set the SDL video mode with width, height and bits-per-pixel bpp. Optional arg flags (see flagstash:video) is supported. Return a new surface.

3.1 Rectangles

— Procedure: rect? obj

Return #t iff obj is an SDL-rectangle object.

— Procedure: make-rect x y width height

Return a rectangle object with location x,y and dimensions width by height.

— Procedure: rect:x obj

Get x from the SDL_Rect * obj.

— Procedure: rect:y obj

Get y from the SDL_Rect * obj.

— Procedure: rect:w obj

Get w from the SDL_Rect * obj.

— Procedure: rect:h obj

Get h from the SDL_Rect * obj.

— Procedure: rect:set-x! obj value

Set x in the SDL_Rect * obj to value.

— Procedure: rect:set-y! obj value

Set y in the SDL_Rect * obj to value.

— Procedure: rect:set-w! obj value

Set w in the SDL_Rect * obj to value.

— Procedure: rect:set-h! obj value

Set h in the SDL_Rect * obj to value.

— Procedure: update-rect surface x [y [w [h]]]

Update surface within a specified rectangle. The second arg can either be an SDL-Rect object, or the second through fifth args are numbers specifying the x, y, width and height of a rectangular area. The return value is unspecified.

— Procedure: update-rects surface ls

On surface, update the rectangles in ls, a list of rectangles. The return value is unspecified.

— Procedure: flip [surface]

Swap double buffers of the default surface, or of surface if specified. The return value is unspecified.

3.2 Colors

— Procedure: color? obj

Return #t iff obj is an SDL-color object.

— Procedure: make-color r g b

Return a color object with r, g, and b components.

— Procedure: color:r obj

Get r from the SDL_Color * obj.

— Procedure: color:g obj

Get g from the SDL_Color * obj.

— Procedure: color:b obj

Get b from the SDL_Color * obj.

— Procedure: color:set-r! obj value

Set r in the SDL_Color * obj to value.

— Procedure: color:set-g! obj value

Set g in the SDL_Color * obj to value.

— Procedure: color:set-b! obj value

Set b in the SDL_Color * obj to value.

— Procedure: set-colors! surface colors

Set a portion of the colormap for the 8-bit surface using colors, a vector of SDL-Colors.

— Procedure: set-palette surface flags colors

Set the palette of an 8-bit surface using flags (see flagstash:palette) and colors, a vector of SDL-Colors.

— Procedure: set-gamma redgamma greengamma bluegamma

Set the color gamma function for the display using real numbers redgamma, greengamma and bluegamma.

— Procedure: get-gamma-ramp

Get the gamma translation lookup tables currently used by the display. Each table is a vector of 256 integer values. Return an alist with keys redtable, greentable and bluetable, and values the corresponding vectors. Return #f if unsuccessful.

— Procedure: set-gamma-ramp redtable greentable bluetable

Set the gamma translation lookup tables currently used by the display, for redtable, greentable and bluetable. Each table is an vector of 256 integer values. Return #t if successful.

— Procedure: map-rgb format r [g [b]]

Map a RGB color value to the pixel format. The second arg can be an SDL-Color, otherwise the second through fourth args are red, green and blue values (numbers). Return the mapped components as an unsigned integer.

— Procedure: map-rgba format r g [b [a]]

Map a RGB color value to the pixel format. If the second arg is an SDL-Color, the third is an alpha value (number). Otherwise, the second through fifth args are red, green, blue and alpha values (numbers). Return the mapped components as an unsigned integer.

— Procedure: get-rgb pixel format

Get RGB values from pixel in the specified pixel format. Return an alist with keys r, g and b, with red, green and blue values (numbers), respectively.

— Procedure: get-rgba pixel format

Get RGBA values from pixel in the specified pixel format. Return an alist with keys r, g, b and a, with red, green, blue and alpha values (numbers), respectively.

— Procedure: fill-rect surface rect color

Fill surface rect with color (a number). If rect is #f, fill the entire surface. Return #t if successful.

— Procedure: display-format surface

Return a new surface made by converting surface to the display format. Return #f if not successful.

— Procedure: display-format-alpha surface

Return a new surface made by converting surface to the display format, with an alpha channel. Return #f if not successful.

— Procedure: warp-mouse x y

Set the position of the mouse cursor to x,y. The return value is unspecified.

— Procedure: set-cursor cursor

Set the current mouse cursor to cursor. The return value is unspecified.

— Procedure: get-cursor

Get the current mouse cursor.

— Procedure: show-cursor [query]

Toggle the visibility of the mouse cursor. Return #t if was being displayed before the call, and #f if not. Optional arg query non-#f means to return the current state without toggling.

— Procedure: gl-get-attribute attribute

Return the value of a special SDL/OpenGL attribute.

— Procedure: gl-set-attribute attribute value

Set the special SDL/OpenGL attribute to value. Both args are numbers. The return value is unspecified.

— Procedure: gl-swap-buffers

Swap OpenGL framebuffers/Update Display. The return value is unspecified.

— Procedure: lock-yuv-overlay overlay

Lock the given YUV overlay. Return #f if successful.

— Procedure: unlock-yuv-overlay overlay

Unlock the previously locked YUV overlay. The return value is unspecified.

— Procedure: display-yuv-overlay overlay dstrect

Blit the YUV overlay to the display dstrect over which it was created. Return #t if successful.

3.3 Windowing System Interaction

— Procedure: get-wm-info

Return information on the window manager, as a list of the form: (VERSION SUBSYSTEM DISPLAY WINDOW FSWINDOW WMWINDOW). VERSION is a sub-list of form: (MAJOR MINOR PATCH), where element is an integer. SUBSYSTEM is either the symbol x11, or #f. DISPLAY is a pointer (machine address) of the X11 Display structure, converted to an integer. WINDOW, FSWINDOW and WMWINDOW are Window identifiers (also integers).

— Procedure: set-caption title [icon]

Set the title-bar and icon name of the display window to title and icon (both strings), respectively. If icon is not specified, use title by default.

— Procedure: get-caption

Return an alist with keys title and icon and values the title-bar and icon name of the display window, respectively.

— Procedure: set-icon icon

Set icon for the display window.

— Procedure: iconify-window

Iconify/Minimize the window. Return #t if successful.

— Procedure: toggle-full-screen [surface]

Toggle the default video surface between windowed and fullscreen mode, if supported. Optional arg surface specifies another surface to toggle. Return #t if successful.

— Procedure: grab-input [mode]

Grab mouse and keyboard input. Return new grab state. Optional arg mode (a symbol) specifies the kind of grab, one of query (the default), off or on.

Compatibility Note: Presently, mode can also be an integer, one of -1, 0 or 1. Starting with Guile-SDL 0.5.0 an integer mode will result in a wrong-type-arg error.

— Procedure: get-app-state

Return the current state of the application, a list of symbols. The list may include: `mousefocus', `inputfocus', `active'.

3.4 Surface

— Procedure: make-surface width height [flags]

Return a new surface of dimensions width by height. Optional third arg flags (see flagstash:video) further specifies the surface. Color depth and masks are those for the current video surface.

— Procedure: create-rgb-surface flags width height depth rmask gmask bmask amask

Return an empty surface. The eight arguments, directly analagous to those for SDL_CreateRGBSurface, are: flags (list of symbols, see flagstash:video), width, height, depth, rmask, gmask, bmask, amask (all numbers).

— Procedure: surface:w obj

Get w from the SDL_Surface * obj.

— Procedure: surface:h obj

Get h from the SDL_Surface * obj.

— Procedure: surface:depth obj

Get format->BitsPerPixel from the SDL_Surface * obj.

— Procedure: surface:flags obj
— Procedure: surface-get-format surface

Return a new pixel format, the same used by surface.

— Procedure: surface? obj

Return true iff obj is a surface.

— Procedure: lock-surface surface

Lock surface for direct access. Return #t if successful.

— Procedure: unlock-surface surface

Unlock previously locked surface. The return value is unspecified.

— Procedure: load-bmp file

Return a surface made by loading the bitmap file.

— Procedure: load-image file

Return a surface made by loading the image file. If there are problems, return #f.

— Procedure: string->image s

Return a surface made by loading image data from string s. [WARNING: This procedure is experimental!]

— Procedure: save-bmp surface file

Save surface to file in Windows BMP format. Return #t if successful.

— Procedure: set-color-key! surface flag key

Set surface color key as specified by flag (see flagstash:video) and key.

— Procedure: set-alpha! surface flag [alpha]

Adjust whole-surface alpha as specified by flag (see flagstash:video) and alpha (one of the alpha-enums, or a number 0-255). See Enums and Constants. If flag is #f, ignore alpha completely.

— Procedure: set-clip-rect! surface [rect]

Set surface clipping rectangle to the whole surface. Optional arg rect, if non-#f, specifies a particular rectangle instead of using the whole surface.

— Procedure: get-clip-rect surface

Return the clipping rectangle for surface.

— Procedure: convert-surface surface format [flags]

Convert surface to the same format as another surface. Optional third arg flags is a list of flags (symbols) from the set returned by flagstash:video.

— Procedure: blit-surface src [srcrect [dst [dstrect]]]

Perform a fast blit from the src surface srcrect to the dst surface dstrect. srcrect defaults to x=0, y=0, src surface dimensions. If unspecified dst is taken as the default video surface. dstrect likewise defaults to x=0, y=0, dst surface dimensions.

3.5 Misc Surface Operations

— Procedure: vertical-flip-surface surface

Return a new surface created by flipping surface vertically.

— Procedure: horizontal-flip-surface surface

Return a new surface created by flipping surface horizontally.

— Procedure: vh-flip-surface surface

Return a new surface created by flipping surface both vertically and horizontally.


Next: , Previous: Video, Up: Top

4 Events

— Procedure: flagstash:event-mod

Return the flagstash object for event mod flags. See Enums and Constants.

     KMOD_foo, where foo can be:
     RALT        RMETA       RSHIFT      NUM
     LALT        LMETA       LSHIFT      RESERVED
     CAPS        RCTRL       MODE        LCTRL
     NONE
— Procedure: flagstash:event-mask

Return the flagstash object for event mask flags. See Enums and Constants.

     SDL_fooMASK, where foo can be:
     ACTIVEEVENT
     
     JOYEVENT                    ; logior of 5 SDL_JOY*MASK:
     JOY{AXIS,BALL,HAT}MOTION
     JOYBUTTON{DOWN,UP}
     
     KEYEVENT                    ; logior of 2 SDL_KEY*MASK:
     KEY{DOWN,UP}
     
     MOUSEEVENT                  ; logior of 3 SDL_MOUSE*MASK:
     MOUSEBUTTON{DOWN,UP}
     MOUSEMOTION
     
     QUIT          SYSWMEVENT
     VIDEOEXPOSE   VIDEORESIZE
— Procedure: make-event [type]

Return a new SDL event. Optional arg type is one of the symbols enumerated in the variable event-types. If omitted, the default is SDL_NOEVENT. See Enums and Constants.

— Procedure: make-keysym [sym [mod]]

Return a new keysym. Optional args sym and mod specify one of the event-keys (see Enums and Constants) and any modifiers (from flasgstash:event-mod), respectively.

— Procedure: event:type obj
— Procedure: event:set-type! obj value

4.1 Activity

— Procedure: event:active:gain obj

Get active.gain from the SDL_Event * obj.

— Procedure: event:active:state obj

Get active.state from the SDL_Event * obj.

— Procedure: event:active:set-gain! obj value

Set active.gain in the SDL_Event * obj to value.

— Procedure: event:active:set-state! obj value

Set active.state in the SDL_Event * obj to value.

4.2 Keys

— Procedure: event:key:keysym:sym obj
— Procedure: event:key:keysym:set-sym! obj value
— Procedure: event:key:keysym:mod obj
— Procedure: event:key:keysym:set-mod! obj value
— Procedure: event:key:state obj

Get key.state from the SDL_Event * obj.

— Procedure: event:key:keysym:scancode obj

Get key.keysym.scancode from the SDL_Event * obj.

— Procedure: event:key:keysym:unicode obj

Get key.keysym.unicode from the SDL_Event * obj.

— Procedure: event:key:set-state! obj value

Set key.state in the SDL_Event * obj to value.

— Procedure: event:key:keysym:set-scancode! obj value

Set key.keysym.scancode in the SDL_Event * obj to value.

— Procedure: event:key:keysym:set-unicode! obj value

Set key.keysym.unicode in the SDL_Event * obj to value.

4.3 Motions

— Procedure: event:motion:state obj

Get motion.state from the SDL_Event * obj.

— Procedure: event:motion:x obj

Get motion.x from the SDL_Event * obj.

— Procedure: event:motion:y obj

Get motion.y from the SDL_Event * obj.

— Procedure: event:motion:xrel obj

Get motion.xrel from the SDL_Event * obj.

— Procedure: event:motion:yrel obj

Get motion.yrel from the SDL_Event * obj.

— Procedure: event:motion:set-state! obj value

Set motion.state in the SDL_Event * obj to value.

— Procedure: event:motion:set-x! obj value

Set motion.x in the SDL_Event * obj to value.

— Procedure: event:motion:set-y! obj value

Set motion.y in the SDL_Event * obj to value.

— Procedure: event:motion:set-xrel! obj value

Set motion.xrel in the SDL_Event * obj to value.

— Procedure: event:motion:set-yrel! obj value

Set motion.yrel in the SDL_Event * obj to value.

4.4 Buttons

— Procedure: button? mask

Return #t if buttons specified in mask (an integer) are pressed. Use 1 for left, 2 for middle and 4 for right, combined with logior, to form mask. For example, a value of 5 specifies both left and right buttons.

— Procedure: event:button:button obj

Get button.button from the SDL_Event * obj.

— Procedure: event:button:state obj

Get button.state from the SDL_Event * obj.

— Procedure: event:button:x obj

Get button.x from the SDL_Event * obj.

— Procedure: event:button:y obj

Get button.y from the SDL_Event * obj.

— Procedure: event:button:set-button! obj value

Set button.button in the SDL_Event * obj to value.

— Procedure: event:button:set-state! obj value

Set button.state in the SDL_Event * obj to value.

— Procedure: event:button:set-x! obj value

Set button.x in the SDL_Event * obj to value.

— Procedure: event:button:set-y! obj value

Set button.y in the SDL_Event * obj to value.

4.5 Joysticks

— Procedure: event:jaxis:which obj

Get jaxis.which from the SDL_Event * obj.

— Procedure: event:jaxis:axis obj

Get jaxis.axis from the SDL_Event * obj.

— Procedure: event:jaxis:value obj

Get jaxis.value from the SDL_Event * obj.

— Procedure: event:jaxis:set-which! obj value

Set jaxis.which in the SDL_Event * obj to value.

— Procedure: event:jaxis:set-axis! obj value

Set jaxis.axis in the SDL_Event * obj to value.

— Procedure: event:jaxis:set-value! obj value

Set jaxis.value in the SDL_Event * obj to value.

— Procedure: event:jbutton:which obj

Get jbutton.which from the SDL_Event * obj.

— Procedure: event:jbutton:button obj

Get jbutton.button from the SDL_Event * obj.

— Procedure: event:jbutton:state obj

Get jbutton.state from the SDL_Event * obj.

— Procedure: event:jbutton:set-which! obj value

Set jbutton.which in the SDL_Event * obj to value.

— Procedure: event:jbutton:set-button! obj value

Set jbutton.button in the SDL_Event * obj to value.

— Procedure: event:jbutton:set-state! obj value

Set jbutton.state in the SDL_Event * obj to value.

— Procedure: event:jball:which obj

Get jball.which from the SDL_Event * obj.

— Procedure: event:jball:ball obj

Get jball.ball from the SDL_Event * obj.

— Procedure: event:jball:xrel obj

Get jball.xrel from the SDL_Event * obj.

— Procedure: event:jball:yrel obj

Get jball.yrel from the SDL_Event * obj.

— Procedure: event:jball:set-which! obj value

Set jball.which in the SDL_Event * obj to value.

— Procedure: event:jball:set-ball! obj value

Set jball.ball in the SDL_Event * obj to value.

— Procedure: event:jball:set-xrel! obj value

Set jball.xrel in the SDL_Event * obj to value.

— Procedure: event:jball:set-yrel! obj value

Set jball.yrel in the SDL_Event * obj to value.

— Procedure: event:jhat:which obj

Get jhat.which from the SDL_Event * obj.

— Procedure: event:jhat:hat obj

Get jhat.hat from the SDL_Event * obj.

— Procedure: event:jhat:value obj

Get jhat.value from the SDL_Event * obj.

— Procedure: event:jhat:set-which! obj value

Set jhat.which in the SDL_Event * obj to value.

— Procedure: event:jhat:set-hat! obj value

Set jhat.hat in the SDL_Event * obj to value.

— Procedure: event:jhat:set-value! obj value

Set jhat.value in the SDL_Event * obj to value.

4.6 Resizes

— Procedure: event:resize:w obj

Get resize.w from the SDL_Event * obj.

— Procedure: event:resize:h obj

Get resize.h from the SDL_Event * obj.

— Procedure: event:resize:set-w! obj value

Set resize.w in the SDL_Event * obj to value.

— Procedure: event:resize:set-h! obj value

Set resize.h in the SDL_Event * obj to value.

4.7 Misc

— Procedure: pump-events

Gather events from input devices and update the event queue. The return value is unspecified.

— Procedure: peep-events events numevents action mask

Manage the event queue, depending on action:

SDL_ADDEVENT
Add up to numevents (an integer) events from events (a list) to the back of the event queue.
SDL_PEEKEVENT
Return a count (number less than or equal to numevents) of events at the front of the event queue that match mask (see flagstash:event-mask), without changing the queue.
SDL_GETEVENT
Act like for SDL_PEEKEVENT except return a list of matching events instead of a count, removing them from the queue.

— Procedure: poll-event [event]

Poll for events and return #t if there are any pending. Optional arg event specifies an event object (from make-event) to be filled in with the next event from the queue (if available).

— Procedure: wait-event [event]

Wait indefinitely for and return #f only if there were errors. Optional arg event specifies an event object (from make-event) to be filled in with the next event from the queue.

— Procedure: push-event event

Push event onto the queue. Return 1 for success, 0 if the queue was full, -1 for other errors.

— Procedure: set-event-filter filter

[not yet implemented]

— Procedure: get-event-filter filter

[not yet implemented]

— Procedure: event-state type state

Query or set event type to state. type should be one elements from event-types, and likewise state from event-states. See Enums and Constants. If state is SDL_QUERY, return the current processing state of the specified event.

— Procedure: enable-unicode [enable_p]

Return #t iff UNICODE keyboard translation is enabled. Optional arg enable? if non-#f, enables UNICODE keyboard translation, or disables it if #f.

— Procedure: enable-key-repeat delay interval

Enable or disable keyboard repeat. delay is the initial delay in ms between the time when a key is pressed, and keyboard repeat begins. interval is the time in ms between keyboard repeat events. If delay is 0, keyboard repeat is disabled. Return #t on success.

— Procedure: get-key-state

Return a list of pressed keys (SDLK_* symbols).

— Procedure: get-mod-state

Return the current key modifier state as a list of symbols.

— Procedure: set-mod-state modstate

Set the current key modifier state to modstate, a list of symbols. This does not change the keyboard state, only the key modifier flags. The return value is unspecified.

— Procedure: get-mouse-state

Return the current state of the mouse as an alist with symbolic keys: state, x and y.

— Procedure: get-mouse-relative-state

Return the current relative state of the mouse as an alist symbolic keys: state, x and y.


Next: , Previous: Events, Up: Top

5 Joystick

— Procedure: num-joysticks

Return the number of joysticks.

— Procedure: joystick? obj

Return #t iff obj is a joystick object.

— Procedure: joystick-null? joystick

Return #t iff joystick is a NULL joystick. [What does that mean? –ttn]

— Procedure: joystick-name [n]

Return the name of the default joystick. Optional arg n specifies which joystick to check.

— Procedure: joystick-open [n]

Return a handle to the default joystick opened for use. Optional arg n specifies which joystick to open.

— Procedure: joystick-opened? [n]

Return #t iff the default joystick is opened. Optional arg n specifies which joystick to check.

— Procedure: joystick-index joystick

Return the index of joystick.

— Procedure: joystick-num-axes joystick

Return the number of axes for joystick.

— Procedure: joystick-num-balls joystick

Return the number trackballs for joystick.

— Procedure: joystick-num-hats joystick

Return the number of hats for joystick.

— Procedure: joystick-num-buttons joystick

Return number of buttons for joystick.

— Procedure: joystick-update

Update the state of all Joysticks.

— Procedure: joystick-event-state state

Set the Joystick event processing model to state.

— Procedure: joystick-get-axis joystick axis

For joystick, return state of axis.

— Procedure: joystick-get-ball joystick n

For joystick, return relative motion of trackball n, as an alist with keys dx and dy. On error, return #f.

— Procedure: joystick-get-hat joystick n

For joystick, return state of hat n.

— Procedure: joystick-get-button joystick n

For joystick, return state of button n.

— Procedure: joystick-close joystick

Close a previously opened joystick. The return value is unspecified.


Next: , Previous: Joystick, Up: Top

6 CDROM

— Procedure: cd? obj

Return #t iff obj is a CDROM drive object.

— Procedure: cd-null? cdrom

Return #t iff cdrom is a null pointer. [What does that mean? –ttn]

— Procedure: cd-num-drives

Return the number of CDROM drives.

— Procedure: cd-name [drive]

Return a human-readable, system-dependent identifier (a string) for the CDROM. Optional arg drive is a number specifying which drive.

— Procedure: cd-open [drive]

Open the CDROM drive for access and return its handle. If the drive is unavailable, return #f. Optional arg drive is a number specifying which drive.

— Procedure: cd-status cdrom

Return the current status of the drive cdrom as a symbol, one of: TRAYEMTPY, STOPPED, PLAYING, PAUSED or ERROR.

— Procedure: cd-in-drive? cdrom

Return #t iff there is a CD in drive cdrom.

— Procedure: cd-get-num-tracks cdrom

Return the number of tracks on the CD in drive cdrom.

— Procedure: cd-get-cur-track cdrom

Return the current track on the CD in drive cdrom.

— Procedure: cd-get-cur-frame cdrom

Return the current frame of the CD in drive cdrom.

— Procedure: cd-get-nth-track cdrom [n]

For CD in drive cdrom, return info on track n as an alist or #f if there were problems.

— Procedure: cd-play-tracks cdrom [start_track [start_frame [n_tracks [n_frames]]]]

Play the given CD tracks in drive cdrom. Play the CD starting at start-track and start-frame for ntracks tracks and nframes frames. If both ntrack and nframe are 0, play until the end of the CD. This procedure will skip data tracks, and should only be called after calling cd-status to get track information about the CD. Return #t if successful.

— Procedure: cd-play cdrom start length

Play CD in drive cdrom from start frame for length frames. Return #t if successful.

— Procedure: cd-pause cdrom

Pause the CD in drive cdrom. Return #t if successful.

— Procedure: cd-resume cdrom

Resume (unpause) the CD in drive cdrom. Return #t if successful.

— Procedure: cd-stop cdrom

Stop the CD in drive cdrom. Return #t if successful.

— Procedure: cd-eject cdrom

Eject the CD from drive cdrom. Return #t if successful.

— Procedure: cd-close cdrom

Close the drive cdrom. The return value is unspecified.

— Procedure: cd-msf->frames m [s [f]]

Return frames (an integer) computed fr m, second s and frame f. s and f are optional.

— Procedure: cd-frames->msf frames

Return a minute/second/frames alist made from converting frames (a number).


Next: , Previous: CDROM, Up: Top

7 OpenGL

[todo]


Next: , Previous: OpenGL, Up: Top

8 TrueType

— Procedure: flagstash:ttf

Return the flagstash object for ttf flags. You can pass this object to proc flagstash-flags to get a list of its flags. See Enums and Constants.

     TTF_STYLE_foo, where foo can be:
       BOLD  NORMAL  UNDERLINE  ITALIC
— Procedure: ttf-init

Initialize the SDL_ttf subsystem.

— Procedure: load-font file ptsize

Load a font from file with point size ptsize. Return a handle.

— Procedure: font:style font

Return the style of font (see flagstash:ttf). This font style is implemented by modifying the font glyphs, and doesn't reflect any inherent properties of the truetype font file.

— Procedure: font:set-style! font style

Set font style to style (see flagstash:ttf). This font style is implemented by modifying the font glyphs, and doesn't reflect any inherent properties of the truetype font file.

— Procedure: font:height font

Return the total height of font, usually equal to point size.

— Procedure: font:ascent font

Return the offset from the baseline to the top of font. This is a positive number.

— Procedure: font:descent font

Return the offset from the baseline to the bottom of font. This is a negative number.

— Procedure: font:line-skip font

Return the recommended spacing between lines of text for font.

— Procedure: font:glyph-metrics font ch

Return the metrics (dimensions) of a glyph as an alist. The glyph is a font-specific rendering of char ch. Alist keys are: minx, maxx, miny, maxy and advance. Values are numbers.

— Procedure: font:size-text font text

Return an alist with keys w and h and corresponding values (numbers) representing the width and height of the font-specific rendering of the string text.

— Procedure: font:size-utf8 font text

Return an alist with keys w and h and corresponding values (numbers) representing the width and height of the font-specific rendering of the utf8 string text.

— Procedure: render-text font text fg [bg]

Return a new surface containing the font-specific rendering of the text string. Third argument is the foreground color; optional fourth argument is the background color, or #t if the text is to be blended.

— Procedure: render-utf8 font text fg [bg]

Return a new surface containing a font-specific rendering of the utf8 string text. Third argument is the foreground color; optional fourth argument is the background color, or #t if the text is to be blended.

— Procedure: render-glyph font ch fg [bg]

Return a new surface containing a font-specific rendering of the character ch. Third argument is the foreground color; optional fourth argument is the background color, or #t if the text is to be blended.

— Procedure: ttf-quit

Quit the SDL_ttf subsystem.


Next: , Previous: TrueType, Up: Top

9 Audio

— Procedure: open-audio [freq [format [stereo [chunksize]]]]

Open the mixer with a certain audio format. Optional args freq (number), format (number), stereo (boolean) and chunksize (number) specify those aspects of the device. Return #t if successful.

— Procedure: allocated-channels numchans

Dynamically change the number of channels managed by the mixer to numchans. If decreasing the number of channels, the upper channels are stopped. Return the new number of allocated channels.

— Procedure: query-spec

Return audio device parameters as an alist, or #f if the audio has not yet been opened. Keys are freq (frequency), format, and channels (the number of allocated channels).

— Procedure: load-music file

Load a wave or a music (.mod .s3m .it .xm) file. Return a handle to it.

— Procedure: load-wave file

Load a wave file. Return a handle to it.

— Procedure: reserve-channels num

Reserve the first num channels (0 through num-1) for the application. In other words don't allocate them dynamically to the next sample if requested with a -1 value below. Return the number of reserved channels.

— Procedure: group-channel channel [tag]

Attach to channel a tag. A tag can be assigned to several mixer channels, to form groups of channels. If tag is not specified, or is -1, the tag is removed (actually -1 is the tag used to represent the group of all the channels). Return #t if successful.

— Procedure: group-channels from to [tag]

Assign channels in the range from through to to the default group. Optional arg tag specifies the group to use. Return #t if successful.

— Procedure: group-available [tag]

Return the first available channel in the default group of channels. Optional arg tag specifies the group to check.

— Procedure: group-count [tag]

Return the number of channels in the default group. Optional arg tag specifies the group to check.

— Procedure: group-oldest [tag]

Return the "oldest" sample playing in the default group of channels. Optional arg tag specifies the group to check.

— Procedure: group-newer [tag]

Return the "most recent" (i.e. last) sample playing in the default group of channels. Optional arg tag specifies the group to check.

— Procedure: play-channel chunk [channel [loops [ticks [fade]]]]

Play an audio chunk on a specific channel. If the channel is unspecified or is -1, play on the first free channel. If loops is specified and greater than zero, loop the sound that many times. If loops is -1, loop infinitely (~65000 times). If ticks is specified, stop after that number of ticks. If fade is specified, fade in over that number of milliseconds. Return which channel was used to play the sound.

— Procedure: play-music music [loops [fade]]

Play a music track. Optional args loops and fade are as in play-channel.

— Procedure: volume [volume [which]]

Return the current volume on the default channel. Optional arg volume (a number in the range 0-128) means set the volume to volume and return the original volume. Optional second arg which specifies a chunk or channel to check (or modify) instead of the default. If volume is non-#f and which is #f, modify all channels.

[Here is the original (perhaps clearer) docstring. —ttn]

Set the volume in the range of 0-128 of a specific channel or chunk. If the channel is unspecified or is -1, set volume for all channels. Return the original volume. If the volume is unspecified or is -1, just return the current volume.

— Procedure: music-volume [volume]

Return the current volume. Optional arg volume (a number in the range 0-128) means set the volume to volume.

— Procedure: halt-channel [channel]

Halt playing of the default channel. Optional arg channel specifies a channel to halt.

— Procedure: halt-group [tag]

Halt playing of the default group. Optional arg tag specifies the group to halt.

— Procedure: halt-music

Halt playing of the music.

— Procedure: expire-channel [channel [ticks]]

Turn off expiration for the default channel. Optional arg channel specifies a channel to change. Optional arg ticks (a number) means set the expiration delay to that many milliseconds, rather than turning it off.

— Procedure: fade-out-channel [which [ms]]

Halt a channel, fading it out progressively until silent. Optional arg which specifies a channel to halt. Second optional arg ms specifies the number of milliseconds the fading will take (default 0).

— Procedure: fade-out-group [tag [ms]]

Halt a group, fading it out progressively until silent. Optional arg tag specifies a group to halt. Second optional arg ms specifies the number of milliseconds the fading will take (default 0).

— Procedure: fade-out-music [ms]

Halt the music, fading it out progressively until silent. Optional arg ms specifies the number of milliseconds the fading will take (default 0).

— Procedure: fading-music

Return the fading status of the music. See Enums and Constants.

— Procedure: fading-channel [which]

Return the fading status of the default channel. Optional arg which selects which channel to check. See Enums and Constants.

— Procedure: pause [channel]

Pause the default channel. Optional arg channel selects which channel to pause. Return value unspecified.

— Procedure: resume [channel]

Resume (unpause) the default channel. Optional arg channel selects which channel to resume. Return value unspecified.

— Procedure: paused? [channel]

Return #t if the default channel is paused. Optional arg channel selects a which channel to check.

— Procedure: pause-music

Pause the music. Return value unspecified.

— Procedure: resume-music

Resume (unpause) the music. Return value unspecified.

— Procedure: rewind-music

Rewind the music. Return value unspecified.

— Procedure: paused-music?

Return #t if the music is currently paused.

— Procedure: playing? [channel]

Return #t iff the default channel is playing. Optional arg channel selects which channel to check.

— Procedure: playing-music?

Return #t iff the music is currently playing.

— Procedure: set-music-command command

Stop music and set external music playback command to command, a string.

FWIW, the C header file for the following panning, distance and position procs says:

Setting (channel) to MIX_CHANNEL_POST registers this as a posteffect, and the panning will be done to the final mixed stream before passing it on to the audio device.
— Procedure: set-panning channel l r

Set panning for (stereo) channel with l and r. Both l and r are integers 0–255, inclusive, where 0 is quietest and 255 is loudest.

To get “true” panning, use (set-panning CH N (- 255 N)).

— Procedure: set-distance channel distance

Set the “distance” of channel to distance (integer, 0–255). This controls the location of the sound with respect to the listener.

Distance 0 is overlapping the listener, and 255 is as far away as possible. A distance of 255 does not guarantee silence; in such a case, you might want to try changing the chunk's volume, or just cull the sample from the mixing process with halt-channel.

For efficiency, the precision of this effect may be limited (distances 1 through 7 might all produce the same effect, 8 through 15 are equal, etc).

Setting (distance) to 0 unregisters this effect, since the data would be unchanged.

— Procedure: set-position channel angle

Set the “position” of channel to angle, distance. In this polar coordinate, angle is in degrees (integer modulo 360), and distance is an integer 0–255 (and is treated as in proc set-distance – see notes there).

Angle 0 is due north, and rotates clockwise as the value increases. For efficiency, the precision of this effect may be limited (angles 1 through 7 might all produce the same effect, 8 through 15 are equal, etc).

Setting angle and distance to 0 unregisters this effect, since the data would be unchanged.

Additionally, the C header says:

If the audio device is configured for mono output, then you won't get any effectiveness from the angle; however, distance attenuation on the channel will still occur. While this effect will function with stereo voices, it makes more sense to use voices with only one channel of sound, so when they are mixed through this effect, the positioning will sound correct. You can convert them to mono through SDL before giving them to the mixer in the first place if you like.

— Procedure: close-audio

Close the mixer, halting all playing audio.


Next: , Previous: Audio, Up: Top

10 SDL_gfx by Andreas Schiffler

10.1 Graphics Primitives

— Procedure: draw-point surface x y color

On surface, draw a point at location x,y with color color.

— Procedure: draw-hline surface x1 x2 y color

On surface, draw a horizontal line segment from x1,y to x2,y, with color color.

— Procedure: draw-vline surface x y1 y2 color

On surface, draw a vertical line segment from x,y1 to x,y2, with color color.

— Procedure: draw-rectangle surface x1 y1 x2 y2 color [fill]

On surface, draw a rectangle with opposite points x1,y1 and x2,y2, with color color. Optional arg fill means to fill the rectangle as well.

— Procedure: draw-line surface x1 y1 x2 y2 color

On surface, draw a line segment from x1,y1 to x2,y2, with color color.

— Procedure: draw-aa-line surface x1 y1 x2 y2 color

On surface, draw an anti-aliased line segment from x1,y1 to x2,y2, with color color.

— Procedure: draw-circle surface x y r color [fill]

On surface, draw a circle with center x,y and radius r, with color color. Optional arg fill means to fill the circle as well.

— Procedure: draw-aa-circle surface x y r color

On surface, draw an anti-aliased circle with center x,y and radius r, with color color.

— Procedure: draw-ellipse surface x y rx ry color [fill]

On surface, draw an ellipse with center x,y x-radius rx, y-radius ry, with color color. Optional arg fill means to fill the ellipse as well.

— Procedure: draw-aa-ellipse surface x y rx ry color

On surface, draw an anti-aliased ellipse with center x,y, x-radius rx, y-radius ry, with color color.

— Procedure: draw-pie-slice surface x y rad start end color [fill]

On surface, draw a pie slice with center x,y and radius rad, going from start to end (degrees), with color color. Optional arg fill means to fill the slice as well.

— Procedure: draw-trigon surface x1 y1 x2 y2 x3 y3 color [fill]

On surface, draw a triangle with vertices at x1,y1, x2,y2 and x3,y3, with color color. Optional arg fill means to fill the triangle as well.

— Procedure: draw-aa-trigon surface x1 y1 x2 y2 x3 y3 color

On surface, draw an anti-aliased triangle with vertices at x1,y1, x2,y2 and x3,y3, with color color.

— Procedure: draw-polygon surface vx vy color [fill]

On surface, draw a polygon whose points are specified by corresponding pairs from the uniform vectors vx and vy, in color color. Optional arg fill means to fill the polygon as well.

— Procedure: draw-aa-polygon surface vx vy color

On surface, draw an anti-a