Next: , Previous: Lights, Up: Functions



12.5 LocalState

The local state functions control rendering either for the current state - or the state of the currently grabbed primitive. In fluxus state means the way that things are displayed, either turning on and off rendering features, changing the style of different features, or altering the current transform.

Example
     

12.5.1 (push)

Returns

void

Description

Pushes a copy of the current drawing state to the top of the stack. The drawing state contains information about things like the current colour, transformation and hints.

Example
      (colour (vector 1 0 0)) ; set current colour to red
      (push)                  ; copy and push drawing state
      (colour (vector 0 1 0)) ; set current colour to green
      (draw-cube)             ; draws a green cube
      (pop)				   ; forget old drawing state
      ; current colour is now red again
     

12.5.2 (pop)

Returns

void

Description

Destroys the current drawing state, and sets the current one to be the previously pushed one in the stack. The drawing state contains information about things like the current colour, transformation and hints.

Example
      (colour (vector 1 0 0)) ; set current colour to red
      (push)                  ; copy and push drawing state
      (colour (vector 0 1 0)) ; set current colour to green
      (draw-cube)             ; draws a green cube
      (pop)				   ; forget old drawing state
      ; current colour is now red again
     

12.5.3 (grab object-id)

Returns

void

Description

Grabs the specified object. Once an object has grabbed it's state can be modified using the same commands used to set the current drawing state. (ungrab) needs to be used to return to the normal drawing state. Grabbing can also be stacked, in which case ungrab pops to the last grabbed primitive.

Example
      (colour (vector 1 0 0))      ; set the current colour to red
      (define mycube (build-cube)) ; makes a red cube
      (grab mycube)
      (colour (vector 0 1 0)) ; sets the cubes colour to green
      (ungrab)				   ; return to normal state
     

12.5.4 (ungrab)

Returns

void

Description

Ungrabs the currently grabbed object, and either returns to the normal drawing state, or pops to the last grabbed primitive.

Example
      (colour (vector 1 0 0))      ; set the current colour to red
      (define mycube (build-cube)) ; makes a red cube
      (grab mycube)
      (colour (vector 0 1 0)) ; sets the cubes colour to green
      (ungrab)				   ; return to normal state
     

12.5.5 (apply object-id)

Returns

void

Description

Applies the current object transform to the vertex positions of the supplied object and sets it's transform to identity.

Example
      (rotate (vector 45 0 0))
      (define mycube (build-cube)) ; makes a cube with a rotation
      (apply mycube)  				; applies the rotation to the points of the cube
     

12.5.6 (opacity value)

Returns

void

Description

Sets the opacity of the current drawing state, or the currently grabbed primitive.

Example
      (opacity 0.5)
      (define mycube (build-cube)) ; makes a half transparent cube
     

12.5.7 (shinyness value)

Returns

void

Description

Sets the shinyness of the current drawing state, or the currently grabbed primitive. This value sets the tightness of the specular highlight.

Example
      (shinyness 100)
      (specular (vector 1 1 1)) ; sets the specular colour
      (define mysphere (build-sphere 10 10)) ; makes a shiny cube
     

12.5.8 (colour colour-vector)

Returns

void

Description

Sets the colour of the current drawing state, or the currently grabbed primitive.

Example
      (colour (vector 1 0.5 0.1)) ; mmm orange...
      (define mycube (build-cube)) ; makes an orange cube
     

12.5.9 (wire-colour colour-vector)

Returns

void

Description

Sets the wire frame colour of the current drawing state, or the currently grabbed primitive. Visible with (hint-wire) on most primitives.

Example
      (wire-colour (vector 1 1 0)) ; set yellow as current wire colour
      (hint-wire)
      (define mycube (build-cube)) ; makes a cube with yellow wireframe
     

12.5.10 (specular colour-vector)

Returns

void

Description

Sets the specular colour of the current drawing state, or the currently grabbed primitive.

Example
      (specular (vector 0 0 1)) ; set blue as specular colour
      (define mysphere (build-sphere 10 10)) ; makes a shiny blue sphere
     

12.5.11 (ambient colour-vector)

Returns

void

Description

Sets the ambient colour of the current drawing state, or the currently grabbed primitive.

Example
      (ambient (vector 0 0 1)) ; set blue as ambient colour
      (define mysphere (build-sphere 10 10)) ; makes a boringly blue sphere
     

12.5.12 (opacity value)

Returns

void

Description

Sets the emissive colour of the current drawing state, or the currently grabbed primitive.

Example
      (emissive (vector 0 0 1)) ; set blue as emissive colour
      (define mysphere (build-sphere 10 10)) ; makes an bright blue sphere
     

12.5.13 (identity)

Returns

void

Description

Sets the drawing state transform to identity, on the state stack, or the currently grabbed primitive.

Example
      (push)
      (scale (vector 2 2 2)) ; set the current scale to double in each dimension
      (define mycube (build-cube)) ; make a scaled cube
      (pop)
      (grab mycube)
      (identity) ; erases the transform and puts the cube back to its original state
      (ungrab)
     

12.5.14 (concat matrix)

Returns

void

Description

Concatenates (multiplies) a matrix on to the current drawing state or grabbed primitive.

Example
      (define mymatrix (mrotate (vector 0 45 0))) ; make a matrix
      (concat mymatrix) ; concat it into the current state
      (build-cube) ; make a cube with this rotation
     

12.5.15 (translate vector)

Returns

void

Description

Applies a translation to the current drawing state transform or grabbed primitive.

Example
      (transform (vector 0 1.4 0)) ; translates the current transform up a bit
      (build-cube) ; build a cube with this transform
     

12.5.16 (rotate vector-or-quaternion)

Returns

void

Description

Applies a rotation to the current drawing state transform or grabbed primitive.

Example
      (rotate (vector 0 45 0)) ; turns 45 degrees in the Y axis
      (build-cube) ; build a cube with this transform
     

12.5.17 (scale vector)

Returns

void

Description

Applies a scale to the current drawing state transform or grabbed primitive.

Example
      (scale (vector 0.5 0.5 0.5)) ; scales the current transform to half the size
      (build-cube) ; build a cube with this transform
     

12.5.18 (get-transform)

Returns

matrix-vector

Description

Returns: a matrix representing the current state transform or for the grabbed primitive.

Example
      (translate (vector 1 0 0))
      (display (get-transform))(newline) ; prints the current transform
      (define shape (build-sphere 10 10))
      (grab shape)
      (translate (vector 0 1 0))
      (display (get-transform))(newline) ; prints shape's transform
      (ungrab)
     

12.5.19 (parent primitive-id)

Returns

void

Description

Parents the currently grabbed primitive to the supplied parent primitive. The current primitive will now be moved around with the parent by aquiring all the parent's transforms.

Example
      (define parent-prim (build-cube)) ; make a parent cube
      (translate (vector 2 0 0)) ; move a bit in x
      (parent parent-prim) ; set parent-prim as the current parent
      (define child-prim (build-cube)) ; make a child cube
      (grab parent-prim)
      (rotate (vector 0 45 0)) ; the child will now be moved by this transform in addition to its own
      (ungrab)
     

12.5.20 (line-width value)

Returns

void

Description

Sets the line width (in screen space) of the current drawing state, or the currently grabbed primitive. Affects wireframe and things like that.

Example
      (line-width 5)
      (hint-wire)
      (build-sphere 10 10) ; make a sphere with thick wireframe
     

12.5.21 (point-width value)

Returns

void

Description

Sets the point width (in screen space) of the current drawing state, or the currently grabbed primitive. Affects point rendering and particles in hardware point mode.

Example
      (point-width 5)
      (hint-points)
      (build-sphere 10 10) ; make a sphere with thick points
     

12.5.22 (blend-mode src dst)

Returns

void

Description

Sets the blend mode of the current drawing state, or the currently grabbed primitive. This is the way that alpha is composited to the rendering surface.

Example
      (point-width 5)
      (hint-points)
      (build-sphere 10 10) ; make a sphere with thick points
     

12.5.23 (hint-solid)

Returns

void

Description

Sets the render hints to solid of the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-solid) ; this is the default render style so this isn't too exciting
      (build-cube) ; make a solid rendered cube
     

12.5.24 (hint-wire)

Returns

void

Description

Sets the render hints to wireframe of the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-wire)
      (build-cube) ; make a wirefame rendered cube
     

12.5.25 (hint-normal)

Returns

void

Description

Sets the render hints to display normals in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-normal)
      (build-cube) ; display the normals on this cube
     

12.5.26 (hint-points)

Returns

void

Description

Sets the render hints to display points in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-points)
      (build-cube) ; display the vertex points on this cube
     

12.5.27 (hint-anti-alias)

Returns

void

Description

Sets the render hints to anti-alias in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-anti-alias)
      (build-cube) ; display a smoothed cube
     

12.5.28 (hint-unlit)

Returns

void

Description

Sets the render hints to unlit in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-unlit)
      (build-cube) ; display an unlit cube
     

12.5.29 (hint-vertcols)

Returns

void

Description

Sets the render hints to use vertex colours in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint. Vertex colours override the current (colour) state.

Example
      (hint-vertcols)
      (define mycube (build-cube)) ; make a cube with vertcols enabled
      (grab mycube)
      (pdata-set "c" 0 (vector 0 1 0)) ; set the colour of the first vertex to green
      (ungrab)
     

12.5.30 (hint-box)

Returns

void

Description

Sets the render hints to bounding box display in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-box)
      (build-sphere 10 10) ; make a sphere with bounding box displayed
     

12.5.31 (hint-multitex)

Returns

void

Description

Sets the render hints to use multitexturing in the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-multitexture)
      (multitexture 0 (load-texture "tex1.png"))
      (multitexture 1 (load-texture "tex2.png"))
      (build-sphere 10 10) ; make a sphere with overlayed textures
     

12.5.32 (hint-none)

Returns

void

Description

Clears the render hints in the current drawing state, or the currently grabbed primitive. This allows you mainly to get rid of the default solid style, but also means that you can turn on and off hints without using push or pop.

Example
      (hint-none)
      (hint-wire)
      (build-cube) ; make a cube only visible with wireframe
     

12.5.33 (hint-origin)

Returns

void

Description

Sets the render hints to display the object space origin of the primitive the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-origin)
      (build-sphere 10 10) ; make a sphere with the origin displayed
     

12.5.34 (hint-cast-shadow)

Returns

void

Description

(note: Not yet implemented) Sets the render hints to cast shadows for the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint.

Example
      (hint-origin)
      (build-sphere 10 10) ; make a sphere with the origin displayed
     

12.5.35 (hint-ignore-depth)

Returns

void

Description

Sets the render hints to ignore depth tests for the current drawing state, or the currently grabbed primitive. Render hints change the way that primitives are rendered, but may have different effects - or no effect on certain primitive types, hence the name hint. This feature is useful for rendering transparent objects, as it means objects will be shown behind previously rendered ones.

Example
      (hint-origin)
      (build-sphere 10 10) ; make a sphere with the origin displayed
     

12.5.36 (texture textureid-number)

Returns

void

Description

Sets the texture of the current drawing state, or the currently grabbed primitive. Texture ids can be generated by the load-texture function.

Example
      (texture (load-texture "mytexture.png"))
      (build-sphere 10 10) ; make a sphere textured with mytexture.png
     

12.5.37 (multitexture textureunit-number textureid-number)

Returns

void

Description

Sets the texture of the current drawing state, or the currently grabbed primitive in the same way as the texture function, but allows you to specify the texture unit (0-7) to apply the texture to. Multitexturing allows you to apply different textures and texture coordinates to the same object at once. Texture unit 0 is the default one (which uses the pdata "t" for it's texture coords) texture unit n looks for pdata "tn" - ie multitexture 1 looks for "t1". You need to add these yourself using (pdata-add) or (pdata-copy). Multitexturing is useful when the textures contain alpha, as they can be overlayed, i.e. decals placed on background textures. Note: fluxus needs to be built using scons MULTITEXTURE=1 to enable this feature.

Example
      (define obj (build-sphere 10 10)) ; make a sphere
      (grab obj)
      (multitexture 0 (load-texture "mytextureA.png"))
      (multitexture 1 (load-texture "mytextureB.png"))
      (pdata-add "t1" "v")   ; make some texture coords for texture B
      (pdata-copy "t" "t1")  ; copy them from the default texture coords
      (ungrab)
     

12.5.38 (print-scene-graph)

Returns

void

Description

Prints out the current scene graph, useful for debugging.

Example
      (print-scene-graph) ; exciting...
     

12.5.39 (hide hidden-number)

Returns

void

Description

Sets the hidden state for the grabbed primitive (also affects all child primitives). Hidden primitives can be treated as normal in every way - they just won't be rendered.

Example
      (define obj (build-cube))
      (grab obj)
      (hide 1) ; hide this cube
      (ungrab)
     

12.5.40 (selectable selectable-number)

Returns

void

Description

Sets whether the grabbed primitive can be selected or not using the select command.

Example
      (define obj (build-cube))
      (grab obj)
      (selectable 0) ; now it won't be "seen" by calling select
      (ungrab)
     

12.5.41 (shader vertexprogram-string fragmentprogram-string)

Returns

void

Description

Loads, compiles and sets the GLSL harware shader pair for the current drawing state, or the currently grabbed primitive. Requires OpenGL 2 support. The shader's uniform data can be controlled via shader-set! and all the pdata is sent through as per-vertex attribute data to the shader.

Example
      (push)
      ; assign the shaders to the surface
      (shader "simplevert.glsl" "simplefrag.glsl")
      (define s (build-sphere 20 20))
      (pop)
     
      (grab s)
      ; add and set the pdata - this is then picked up in the vertex shader
      ; as an input attribute called "testcol"
      (pdata-add "testcol" "v")
      (set-cols (pdata-size))
      (ungrab)
     
      (define (animate)
          (grab s)
      	; animate the deformamount uniform input parameter
          (shader-set! (list "deformamount" (cos (time))))
          (ungrab))
     
      (every-frame (animate))

12.5.42 (shader-set! argument-list)

Returns

void

Description

Sets the uniform shader parameters for the GLSL shader. The list consists of token-string value pairs, which relate to the corresponding shader parameters names and values.

Example
      (push)
      ; assign the shaders to the surface
      (shader "simplevert.glsl" "simplefrag.glsl")
      (define s (build-sphere 20 20))
      (pop)
     
      (grab s)
      ; add and set the pdata - this is then picked up in the vertex shader
      ; as an input attribute called "testcol"
      (pdata-add "testcol" "v")
      (set-cols (pdata-size))
      (ungrab)
     
      (define (animate)
          (grab s)
      	; animate the deformamount uniform input parameter
          (shader-set! (list "deformamount" (cos (time))))
          (ungrab))
     
      (every-frame (animate))