2d Graphics with syndicate-gl
1 Creating Dataspaces
2d-dataspace
spawn-keyboard-integrator
2 Changing the State
update-scene
update-sprites
3 Data Structures
window
frame-event
key-event
key-pressed
scene
sprite
make-sprite
request-gc
simple-sprite
4 Instructions
6.12

2d Graphics with syndicate-gl

 (require syndicate-gl/2d) package: syndicate

1 Creating Dataspaces

procedure

((2d-dataspace [#:width width    
  #:height height    
  #:exit? exit?])    
  boot-actions ...)  any/c
  width : number? = 640
  height : number? = 480
  exit? : boolean? = #t
  boot-actions : action?
Create and run a frame% with dimensions width and height controlled by a Syndicate dataspace. The dataspace is initialized with the given boot-actions. Runs (blocking) while the frame% is active. If exit? is true, calls (exit 0) once the dataspace exits.

procedure

(spawn-keyboard-integrator [#:meta-level meta-level])  actor?

  meta-level : natural-number/c = 1
KeyboardIntegrator. Integrates key-events into key-pressed assertions. The meta-level must point to the root of the 2d dataspace, which defaults to assuming is one level removed.

2 Changing the State

procedure

(update-scene prelude    
  postlude    
  [#:meta-level meta-level])  patch?
  prelude : (listof (sealof (listof instruction)))
  postlude : (listof (sealof (listof instruction)))
  meta-level : natural-number/c = 1
Create a patch retracting any previous scene assertion and asserting a new scene from the prelude and postlude instructions. The meta-level must point to the root of the 2d dataspace, which defaults to assuming is one level removed.

procedure

(update-sprites [#:meta-level meta-level]    
  sprites ...)  patch?
  meta-level : natural-number/c = 1
  sprites : sprite?
Create a patch retracting any previous sprite assertion(s) and asserting each of sprites. The meta-level must point to the root of the 2d dataspace, which defaults to assuming is one level removed.

3 Data Structures

struct

(struct window (width height))

  width : number?
  height : number?
Shared state maintained by dataspace. Describes current window dimensions.

struct

(struct frame-event (counter
    timestamp
    elapsed-ms
    target-frame-rate))
  counter : any/c
  timestamp : any/c
  elapsed-ms : any/c
  target-frame-rate : any/c
Message sent by dataspace. Describes frame about to be rendered.

struct

(struct key-event (code press? key))

  code : (or/c char? key-code-symbol?)
  press? : boolean?
  key : (sealof (instanceof/c key-event%))
Message sent by dataspace. Describes a key event. key is a sealed key-event%. press? is #t when the key is pressed (or autorepeated!), and #f when it is released.

struct

(struct key-pressed (code))

  code : (or/c char? key-code-symbol?)
Assertion. Indicates that the named key is held down. See role KeyboardIntegrator and spawn-keyboard-integrator.

struct

(struct scene (prelude postlude))

  prelude : (sealof (listof instruction))
  postlude : (sealof (listof instruction))
Shared state maintained by program. prelude and postlude are to be sealed instruction lists. It is an error to have more than exactly one active such record at a given time.

struct

(struct sprite (z instructions))

  z : number?
  instructions : (sealof (listof instruction))
Shared state maintained by program. z is to be a number, negative toward camera. instructions to be a sealed instruction list.

procedure

(make-sprite z instructions)  sprite?

  z : number?
  instructions : (listof any/c)
Create a sprite from a z number and a list of instructions.

struct

(struct request-gc ())

Message. Requests that the OpenGL loop perform a major garbage-collection while *pausing the simulation’s real-time correspondence*. This lets a GC take place without such severe simulation glitches as happen when doing it in-world.

procedure

(simple-sprite z x y w h i)  sprite?

  z : number?
  x : number?
  y : number?
  w : number?
  h : number?
  i : 
(or/c (instanceof/c bitmap%)
      pict?
      image?)
Create a sprite from image i at position (x, y) with width w, height h, and z-index z.

4 Instructions

'(rotate degrees) where degrees is a number?

'(scale x y) where x and y are both number?-s

'(translate x y) where x and y are both number?-s

'(color r g b a) where r, g, b, and a are color-number?-s

'(texture i) where i is a (or/c (instanceof/c bitmap%) pict? image?)

'(push-matrix instr ...) where each instr is an instruction

'(begin instr ...) where each instr is an instruction