The local state functions control rendering either for the current state - or the state of the current 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.
Returns void
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. This function has been superseded by (with-state).
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
Returns void
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. This function has been superseded by (with-state).
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
Returns void
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. This function has been superseded by (with-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
Returns void
Ungrabs the current object, and either returns to the normal drawing state, or pops to the last grabbed primitive. This function has been superseded by (with-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
Returns void
Applies the current object transform to the vertex positions of the current object and sets it's transform to identity. Will also use the optional id passed in for the aniquated version of this command
Example
(rotate (vector 45 0 0)) (define mycube (build-cube)) ; makes a cube with a rotation (with-primitive mycube (apply-transform)) ; applies the rotation to the points of the cube
Returns void
Sets the opacity of the current drawing state, or the current primitive.
Example
(opacity 0.5) (define mycube (build-cube)) ; makes a half transparent cube
Returns void
Sets the wireframe opacity of the current drawing state, or the current primitive.
Example
(hint-none) (hint-wire) (backfacecull 0) (line-width 5) (wire-colour (vector 1 1 1)) (wire-opacity 0.5) (build-cube) ; makes a half transparent wireframe cube
Returns void
Sets the shinyness of the current drawing state, or the current 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
Returns void
Sets the colour of the current drawing state, or the current primitive.
Example
(colour (vector 1 0.5 0.1)) ; mmm orange... (define mycube (build-cube)) ; makes an orange cube
Returns void
Changes the way Fluxus interprets colour data for the current drawing state, or the current primitive. Colourmode symbols can consist of: rgb hsv
Example
(clear) (colour-mode 'hsv) (for ((x (in-range 0 10))) (translate (vector 1 0 0)) (colour (vector (/ x 10) 1 1)) (build-cube))
Returns vector
Converts the RGB colour to HSV.
Example
(rgb->hsv (vector 1 0.5 0.1))
Returns vector
Converts the HSV colour to RGB.
Example
(clear) (for* ((x (in-range 0 10)) ; builds a 10x10 HSV colour pattern (y (in-range 0 10))) (identity) (translate (vector x y 0)) (colour (hsv->rgb (vector (/ x 10) (/ y 10) 1))) (build-cube))
Returns void
Sets the wire frame colour of the current drawing state, or the current 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
Returns void
Sets the normals frame colour of the current drawing state, or the current primitive. Visible with (hint-normal) on most primitives.
Example
(normal-colour (vector 1 1 0)) ; set yellow as current normals colour (hint-normal) (define mycube (build-cube)) ; makes a cube with yellow wireframe
Returns void
Sets the specular colour of the current drawing state, or the current primitive.
Example
(specular (vector 0 0 1)) ; set blue as specular colour (define mysphere (build-sphere 10 10)) ; makes a shiny blue sphere
Returns void
Sets the ambient colour of the current drawing state, or the current primitive.
Example
(ambient (vector 0 0 1)) ; set blue as ambient colour (define mysphere (build-sphere 10 10)) ; makes a boringly blue sphere
Returns void
Sets the emissive colour of the current drawing state, or the current primitive.
Example
(emissive (vector 0 0 1)) ; set blue as emissive colour (define mysphere (build-sphere 10 10)) ; makes an bright blue sphere
Returns void
Sets the drawing state transform to identity, on the state stack, or the current primitive.
Example
(define mycube (with-state (scale (vector 2 2 2)) ; set the current scale to double in each dimension (build-cube))) ; make a scaled cube (with-primitive mycube (identity)) ; erases the transform and puts the cube back to its original state
Returns void
Concatenates (multiplies) a matrix on to the current drawing state or current 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
Returns void
Applies a translation to the current drawing state transform or current primitive.
Example
(translate (vector 0 1.4 0)) ; translates the current transform up a bit (build-cube) ; build a cube with this transform
Returns void
Applies a rotation to the current drawing state transform or current primitive.
Example
(rotate (vector 0 45 0)) ; turns 45 degrees in the Y axis (build-cube) ; build a cube with this transform
Returns void
Applies a scale to the current drawing state transform or current 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
Returns matrix-vector
Returns a matrix representing the current state transform or for the current primitive.
Example
(clear) ; build a hierarchy (define a (with-state (colour (vector 1 0.5 0.5)) (build-cube))) (define b (with-state (colour (vector 0.5 1 0.5)) (parent a) (translate (vector 2 0 0)) (build-cube))) (define c (with-state (colour (vector 0.5 0.5 1)) (parent b) (translate (vector 2 0 0)) (build-cube))) (define (animate) ; animate the heirarchy (with-primitive a (rotate (vector 0 0 (sin (time))))) (with-primitive b (rotate (vector 0 0 (sin (time))))) (with-primitive c (rotate (vector 0 0 (sin (time))))) ; position a yellow sphere with c's local transform (with-state (concat (with-primitive c (get-transform))) (opacity 0.5) (colour (vector 1 1 0)) (draw-sphere)) ; position a purple sphere with c's global transform (with-state (concat (with-primitive c (get-global-transform))) (opacity 0.5) (colour (vector 1 0 1)) (draw-sphere))) (every-frame (animate))
Returns matrix-vector
Returns a matrix representing the current global transform for the current primitive.
Example
(clear) ; build a hierarchy (define a (with-state (colour (vector 1 0.5 0.5)) (build-cube))) (define b (with-state (colour (vector 0.5 1 0.5)) (parent a) (translate (vector 2 0 0)) (build-cube))) (define c (with-state (colour (vector 0.5 0.5 1)) (parent b) (translate (vector 2 0 0)) (build-cube))) (define (animate) ; animate the heirarchy (with-primitive a (rotate (vector 0 0 (sin (time))))) (with-primitive b (rotate (vector 0 0 (sin (time))))) (with-primitive c (rotate (vector 0 0 (sin (time))))) ; position a yellow sphere with c's local transform (with-state (concat (with-primitive c (get-transform))) (opacity 0.5) (colour (vector 1 1 0)) (draw-sphere)) ; position a purple sphere with c's global transform (with-state (concat (with-primitive c (get-global-transform))) (opacity 0.5) (colour (vector 1 0 1)) (draw-sphere))) (every-frame (animate))
Returns void
Parents the current 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)
Returns void
Sets the line width (in screen space) of the current drawing state, or the current primitive. Affects wireframe and things like that.
Example
(line-width 5) (hint-wire) (build-sphere 10 10) ; make a sphere with thick wireframe
Returns void
Sets the point width (in screen space) of the current drawing state, or the current 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
Returns void
Sets the blend mode of the current drawing state, or the current primitive. This is the way that alpha is composited to the rendering surface. Blendmode symbols can consist of: zero one dst-color one-minus-dst-color src-alpha one-minus-src-alpha dst-alpha one-minus-dst-alpha Also src-alpha-saturate as an option for the source blendmode only.
Example
; list out all the possible blendmodes (define src-blend (vector 'zero 'one 'dst-color 'one-minus-dst-color 'src-alpha 'one-minus-src-alpha 'dst-alpha 'one-minus-dst-alpha 'src-alpha-saturate)) (define dst-blend (vector 'zero 'one 'src-color 'one-minus-src-color 'src-alpha 'one-minus-src-alpha 'dst-alpha 'one-minus-dst-alpha)) ; picks a random element (define (pick-rnd-item l) (vector-ref l (random (vector-length l)))) ; make lots of random spheres (define (rnd-sphere n) (push) (hint-depth-sort) (opacity 0.5) (colour (vector (flxrnd) (flxrnd) (flxrnd))) ; set a random blendmode (blend-mode (pick-rnd-item src-blend) (pick-rnd-item dst-blend)) (translate (vector (flxrnd) (flxrnd) (flxrnd))) (scale (vector 0.1 0.1 0.1)) (build-sphere 10 10) (pop) (if (zero? n) 0 (rnd-sphere (- n 1)))) (clear) (clear-colour (vector 0.5 0.5 0.5)) (rnd-sphere 100)
Returns void
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. The following symbols set the render hints of the current drawing state, or the current primitive. 'solid - solid rendering 'wire - wireframe 'normal - display normals 'points - display points 'anti-alias - anti-alias lines 'box - display bounding box 'vertcols - use vertex colours, overrides the current (colour) state 'origin - display object space origin 'cast-shadow - cast shadow 'depth-test - use depth tests, it is useful to switch off for rendering transparent objects, as it means objects will be shown behind previously rendered ones. 'depth-sort - depth sort 'lazy-parent - prevent this primitive passing it's transform to it's children 'cull-ccw - flips the faces which get backface culled 'cull-cw - backface cull clockwise winding order faces (default) 'wire-stippled - stippled wireframe 'sphere-map - render objects as if they were perfecly reflective 'frustum-cull - turn frustum culling, when using frustum culling, make sure you call (recalc-bb) on the primitive too. 'normalise - if the current state transform contains a scale transformation, transformed normals might not be unit length, resulting in undesirable lighting problems. This hint makes all normals unit length after they are transformed. This is required if the current state transform contains nonuniform scaling. 'blending - use blending, useful to disable if objects with blending rendered into a pixelprimitive. 'zwrite - Enables/disables z writes. Useful to disable for sometimes hacking transparency. 'lit - turn on lighting 'all - all of the hints above
Example
(clear) (hint-on 'wire 'anti-alias 'origin) (hint-off 'solid) (build-cube)
Returns void
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. (hint-off) disables the render hints of the current drawing state, or the current primitive. Check (hint-on) for more information on possible hint symbols.
Example
(clear) (hint-on 'wire 'anti-alias 'origin) (hint-off 'solid) (build-cube)
Returns void
Sets the render hints to solid of the current drawing state, or the current 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
Returns void
Sets the render hints to wireframe of the current drawing state, or the current 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
Returns void
Sets the render hints to stippled wireframe of the current drawing state, or the current primitive.
Example
(hint-none) (hint-wire-stippled) (build-cube) ; make a stippled wirefame cube
Returns void
Sets the render hints to turn frustum culling on for the current drawing state, or the current 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. When using frustum culling, make sure you call (recalc-bb) on the primitive too.
Example
(hint-frustum-cull)
Returns void
If the current state transform contains a scale transformation, transformed normals might not be unit length, resulting in undesirable lighting problems. (hint-normalise) makes all normals unit length after they are transformed. This is required if the current state transform contains nonuniform scaling.
Example
(clear) (hint-normalise) (build-cube) ; non uniform scaling (with-primitive (build-cube) (translate #(.5 0 0)) (scale #(3 1 1)) (translate #(.5 0 0))) ; uniform scaling (with-primitive (build-cube) (translate #(0 0 2)) (scale 2))
Returns void
Disables blending. Useful if objects with blending rendered into a pixelprimitive.
Example
(clear) (hint-wire) (scale #(9.8 8 1)) (translate #(-1 -.5 0)) (define p0 (build-pixels 512 512 #t)) (with-pixels-renderer p0 (hint-ignore-depth) (with-primitive (build-particles 2048) (pdata-map! (lambda (p) (vmul (crndvec) 2)) "p") (pdata-map! (lambda (c) #(1 .5)) "c"))) (hint-noblend) (translate #(1 0 0)) (define p1 (build-pixels 512 512 #t)) (with-pixels-renderer p1 (hint-ignore-depth) (with-primitive (build-particles 2048) (pdata-map! (lambda (p) (vmul (crndvec) 2)) "p") (pdata-map! (lambda (c) #(1 .5)) "c")))
Returns void
Disables z writes. Useful for sometimes hacking transparency.
Example
(clear) (hint-noblend)
Returns void
Factor specifies a multiplier for each bit in the line stipple pattern. Pattern specifies a 16-bit integer whose bit pattern determines which fragments of a line will be drawn when the line is rasterized.
Example
(hint-none) (hint-wire-stippled) (line-pattern 4 #x0aaaa) (build-cube) ; make a stippled wirefame cube
Returns void
Sets the render hints to display normals in the current drawing state, or the current 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
Returns void
Sets the render hints to display points in the current drawing state, or the current 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
Returns void
Sets the render hints to anti-alias in the current drawing state, or the current 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
Returns void
Sets the render hints to unlit in the current drawing state, or the current 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
Returns void
Sets the render hints to use vertex colours in the current drawing state, or the current 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
(clear) (hint-vertcols) (define mycube (build-cube)) ; make a cube with vertcols enabled (with-primitive mycube (pdata-map! (lambda (c) (rndvec)) ; randomise the vertcols "c"))
Returns void
Sets the render hints to bounding box display in the current drawing state, or the current 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
Returns void
Clears the render hints in the current drawing state, or the current 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
Returns void
Sets the render hints to display the object space origin of the primitive in the current drawing state, or the current 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
Returns void
(note: Not yet implemented) Sets the render hints to cast shadows for the current drawing state, or the current 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
Returns void
Sets the render hints to depth sort for the current drawing state, or the current 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-depth-sort) (build-sphere 10 10)
Returns void
Sets the render hints to ignore depth tests for the current drawing state, or the current 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
(clear) (with-state (hint-ignore-depth) (opacity 0.6) (with-state (colour (vector 1 0 0)) (build-cube)) (with-state (colour (vector 0 1 0)) (translate (vector 1 0 0)) (build-cube)))
Returns void
Sets the render hints to prevent this primitive passing it's transform to it's children. 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-lazy-parent) (build-sphere 10 10) ; make a sphere with the origin displayed
Returns void
Flips the faces which get backface culled
Example
(hint-cull-ccw) (build-sphere 10 10) ; make an inside out
Returns void
Sets the render hints to render objects as if they were perfecly reflective for the current drawing state, or the current primitive.
Example
(clear) (hint-sphere-map) (texture (load-texture "test.png")) (define p (build-torus 1 2 20 20)) (every-frame (with-primitive p (rotate #(.543 .59 .87))))
Returns void
Sets the texture of the current drawing state, or the current 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
Returns boolean
Checks if the texture is in high-performance memory.
Example
(define t (load-texture "test.png")) (display (is-resident? t))(newline) ; usually texture is not resident until used
Returns void
You can provide hints to the OpenGL implementation to decide texture residency by setting the texture’s priority. Priority is between 0.0 and 1.0. A low priority tells the that this texture object should be left out of resident memory whenever space becomes tight. A higher priority (such as 1.0) tells the implementation that you want the texture object to remain resident if possible, even if the texture seems to be used infrequently. Bear in mind that texture priority is only a hint. Some OpenGL implementations are known to ignore them completely.
Example
(define t (load-texture "test.png")) (set-texture-priority t 1.0) (display (is-resident? t))(newline)
Returns void
Sets the texture of the current drawing state, or the current 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.
Example
(clear) (define p (build-torus 1 2 20 20)) (with-primitive p (multitexture 0 (load-texture "refmap.png")) (multitexture 1 (load-texture "transp.png")))
Returns void
Prints out the current scene graph, useful for debugging.
Example
(print-scene-graph) ; exciting...
Returns void
Sets the hidden state for the current 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)
Returns void
Sets the hidden state for the current primitive, with the current camera (also affects all child primitives). Allows you to turn off rendering for primitives under different cameras
Example
(define obj (build-cube)) (with-primitive obj (camera-hide 1)) ; hide this cube
Returns void
Sets whether the current 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)
Returns void
Turns backface culling on or off. Backface culling speeds up rendering by removing faces not orientated towards the camera. Defaults to on, but this is not always desired, eg for double sided polygons.
Example
(backfacecull 0)
Returns void
Loads, compiles and sets the GLSL hardware shader pair for the current drawing state, or the current 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
; you need to have built fluxus with GLSL=1 (clear) (define s (with-state ; assign the shaders to the surface (shader "simple.vert.glsl" "simple.frag.glsl") (build-sphere 20 20))) (with-primitive 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 the testcol pdata with a random colour for every vertex (pdata-map! (lambda (c) (rndvec)) "testcol")) (define (animate) (with-primitive s ; animate the deformamount uniform input parameter (shader-set! (list "deformamount" (cos (time)))))) (every-frame (animate))
Returns void
Same as shader, but uses the supplied strings as shader sourcecode. This allows you to embed GLSL shader source inside your scheme scripts.
Example
; you need to have built fluxus with GLSL=1
Returns void
Clears the shader cache.
Example
(clear-shader-cache)
Returns void
Sets the uniform shader parameters for the GLSL shader. Parameters are keyword value pairs which relate to the corresponding shader parameter name and value. (shader-set!) also accepts a list consisting of token-string value pairs for backward compatibity.
Example
(clear) (define s (with-state ; assign the shaders to the surface (shader "simple.vert.glsl" "simple.frag.glsl") (build-sphere 20 20))) (with-primitive 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 the testcol pdata with a random colour for every vertex (pdata-map! (lambda (c) (rndvec)) "testcol")) (define (animate) (with-primitive s ; animate the deformamount uniform input parameter (shader-set! #:deformamount (cos (time))))) (every-frame (animate))
Returns void
Sets the current texture state for the specified texture unit. This state controls how the texture is applied to the surface of the object, and how it's filtered in texels, or miplevels. The texture unit is used if you are using multitexturing - the default texture unit is 0. You may need to read up a bit on OpenGL or experiment to find out more about these options.
Example
; parameters are the following: ; tex-env : [modulate decal blend replace] ; min : [nearest linear nearest-mipmap-nearest linear-mipmap-nearest linear-mipmap-linear] ; mag : [nearest linear] ; wrap-s : [clamp repeat] ; wrap-t : [clamp repeat] ; wrap-r : [clamp repeat] (for cube maps) ; border-colour : (vector of length 4) ; priority : real number 0 -> 1 ; env-colour : (vector of length 4) ; min-lod : real number (for mipmap blending - default -1000) ; max-lod : real number (for mipmap blending - default 1000) (texture-params 0 '(min nearest mag nearest))