factor/contrib/x11/examples/lindenmayer/viewer.factor

74 lines
2.1 KiB
Factor
Raw Normal View History

2006-01-12 03:19:51 -05:00
USING: kernel alien math arrays sequences opengl namespaces concurrency
xlib x x11 gl concurrent-widgets lindenmayer ;
2006-02-11 11:03:02 -05:00
IN: lindenmayer
2006-01-12 03:19:51 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
USE: sequences
: >float-array ( seq -- )
2006-02-07 02:22:19 -05:00
dup length "float" <c-array> swap dup length >array
[ pick set-float-nth ] 2each ;
2006-01-12 03:19:51 -05:00
USE: lindenmayer
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2006-02-11 11:03:02 -05:00
SYMBOL: camera-position { 5 5 5 } camera-position set-global
SYMBOL: camera-focus { 0 0 0 } camera-focus set-global
SYMBOL: camera-up { 0 1 0 } camera-up set-global
2006-01-12 03:19:51 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2006-02-11 11:03:02 -05:00
lparser-dialect "" result set-global
2006-02-07 02:22:19 -05:00
2006-02-11 11:03:02 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2006-02-07 02:22:19 -05:00
2006-01-12 03:19:51 -05:00
: display ( -- )
GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
2006-02-11 11:03:02 -05:00
glLoadIdentity
camera-position get first3 camera-focus get first3 camera-up get first3
gluLookAt
2006-02-11 11:03:02 -05:00
reset result get save-state interpret restore-state glFlush ;
2006-01-12 03:19:51 -05:00
: reshape ( { width height } -- )
>r 0 0 r> [ ] each glViewport
GL_PROJECTION glMatrixMode
glLoadIdentity -1.0 1.0 -1.0 1.0 1.5 200.0 glFrustum
GL_MODELVIEW glMatrixMode
display ;
2006-02-11 11:03:02 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: init ( -- ) axiom get result set display ;
: iterate ( -- ) result [ rewrite ] change display ;
2006-01-12 03:19:51 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2006-02-11 11:03:02 -05:00
: setup-window ( -- )
2006-01-12 03:19:51 -05:00
f initialize-x
create-pwindow
[ drop reshape ] over set-pwindow-resize-action
[ 2drop display ] over set-pwindow-expose-action
window-id win set
ExposureMask StructureNotifyMask bitor select-input
{ 500 500 } resize-window { 0 0 } move-window map-window
[ GLX_RGBA ] choose-visual create-context make-current
0.0 0.0 0.0 0.0 glClearColor
GL_SMOOTH glShadeModel
GL_FRONT_AND_BACK GL_SPECULAR { 1.0 1.0 1.0 1.0 } >float-array glMaterialfv
GL_FRONT_AND_BACK GL_SHININESS { 50.0 } >float-array glMaterialfv
GL_LIGHT0 GL_POSITION { 1.0 1.0 1.0 0.0 } >float-array glLightfv
GL_LIGHTING glEnable
GL_LIGHT0 glEnable
GL_DEPTH_TEST glEnable
2006-02-11 11:03:02 -05:00
[ concurrent-event-loop ] spawn ;