factor/contrib/x11/examples/double.factor

57 lines
1.4 KiB
Factor
Raw Normal View History

2005-12-30 21:35:38 -05:00
USING: kernel sequences namespaces math io opengl concurrency
x xlib x11 gl concurrent-widgets ;
2005-12-30 20:53:19 -05:00
SYMBOL: loop-action
[ ] loop-action set
SYMBOL: spin
0.0 spin set
: init ( -- ) 0.0 0.0 0.0 0.0 glClearColor GL_FLAT glShadeModel ;
: display ( -- )
GL_COLOR_BUFFER_BIT glClear
glPushMatrix
spin get 0.0 0.0 1.0 glRotatef
1.0 1.0 1.0 glColor3f
-25.0 -25.0 25.0 25.0 glRectf
glPopMatrix
2005-12-30 21:35:38 -05:00
swap-buffers ;
2005-12-30 20:53:19 -05:00
: spin-display ( -- )
spin get 2.0 + spin set
spin get 360.0 > [ spin get 360.0 - spin set ] when
display ;
: reshape ( { width height } -- )
2005-12-30 21:35:38 -05:00
>r 0 0 r> [ ] each glViewport
2005-12-30 20:53:19 -05:00
GL_PROJECTION glMatrixMode glLoadIdentity
-50.0 50.0 -50.0 50.0 -1.0 1.0 glOrtho
GL_MODELVIEW glMatrixMode glLoadIdentity ;
: mouse ( event -- )
2005-12-30 21:35:38 -05:00
{ { [ dup XButtonEvent-button Button1 = ]
[ [ spin-display ] loop-action set drop "Button1 pressed" print ] }
{ [ dup XButtonEvent-button Button2 = ]
2005-12-30 20:53:19 -05:00
[ [ ] loop-action set drop ] }
{ [ t ] [ drop ] } } cond ;
2005-12-30 21:35:38 -05:00
: loop ( -- ) loop-action get call loop ;
2005-12-30 20:53:19 -05:00
f initialize-x
create-pwindow
2005-12-30 21:35:38 -05:00
[ drop reshape "window resized" print ] over set-pwindow-resize-action
[ drop mouse "button pressed" print ] over set-pwindow-button-action
2005-12-30 20:53:19 -05:00
window-id win set
2005-12-30 21:35:38 -05:00
StructureNotifyMask ButtonPressMask bitor select-input
2005-12-30 20:53:19 -05:00
{ 250 250 } resize-window { 100 100 } move-window map-window
[ GLX_RGBA GLX_DOUBLEBUFFER ] choose-visual create-context make-current
2005-12-30 21:35:38 -05:00
init
{ 250 250 } reshape
! [ concurrent-event-loop ] spawn
! [ loop ] spawn