[plt-scheme] graphics states and Scheme

From: Dave Griffiths (dave at pawfal.org)
Date: Wed Jul 4 08:39:56 EDT 2007

Hi all,

As mentioned earlier, I'm writing a game engine[1] for PLT Scheme.
Something I've been meaning to ask here for a while (and touched apon
briefly in the past) is that I'm interested in thinking about different
ways to specify graphics in Scheme than my highly and unashamedly
imperative graphics state scene description, which looks like this:

(colour (vector 1 0 0))   ; set the current colour to red
(rotate (vector 45 0 0))  ; rotate the current transform 45 degrees
(build-cube)              ; adds a cube primitive to the scenegraph with the
                          ; current state - it will be red and rotated

(push)                    ; push the state stack
(translate (vector 0 1 0)); move up in y axis by 1
(build-cube)              ; makes a red rotated cube, translated up by 1
(pop)                     ; pop the state stack

(build-cube)              ; will be the same as the first cube (the state
                          ; containing the translate has been popped off
                          ; the stack)

You can also change states once primitives are stored in the scenegraph -
to allow animation:

(define mycube (build-cube)) ; builds the cube using the current state

... do stuff ...

... called every frame ...
(grab mycube)             ; following commands now set to mycube's state
(rotate (vector 1 0 0))   ; rotate it a bit in the x axis
(ungrab)                  ; grabs can be nested

So this seems to work well, and is very standard stuff for scene
description. The main point is that it reduces the overhead of specifying
and sending data, as (I think) the full functional approach would be to
specify the entire state as arguments each time you build a new primitive.
For animation you would also need to specify the entire scene each frame
for animation rather than using a scenegraph (fluxus has an immediate mode
for doing this, and it is useful - but it's much slower for obvious

I'm fairly happy the way things are, but I'd really like to know if this
would currently be considered 'bad style' and if so, are there are other
ways which would be better for simplicity and efficiency.



[1] http://www.pawfal.org/fluxus

Posted on the users mailing list.