2 USING: alien.c-types alien.data arrays colors grouping kernel
3 locals math math.vectors namespaces opengl opengl.gl opengl.glu
4 sequences sequences.generalizations shuffle ;
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 : do-state ( mode quot -- ) swap glBegin call glEnd ; inline
11 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16 T{ rgba f 0 0 0 1 } stroke-color set-global
17 T{ rgba f 1 1 1 1 } fill-color set-global
19 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22 GL_FRONT_AND_BACK GL_FILL glPolygonMode
23 fill-color get gl-color ;
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 GL_FRONT_AND_BACK GL_LINE glPolygonMode
29 stroke-color get gl-color ;
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 : gl-vertex-2d ( vertex -- ) first2 glVertex2d ;
35 : gl-vertices-2d ( vertices -- ) [ gl-vertex-2d ] each ;
37 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39 : point* ( x y -- ) stroke-mode GL_POINTS [ glVertex2d ] do-state ;
40 : point ( point -- ) stroke-mode GL_POINTS [ gl-vertex-2d ] do-state ;
41 : points ( points -- ) stroke-mode GL_POINTS [ gl-vertices-2d ] do-state ;
43 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 : line** ( x y x y -- )
46 stroke-mode GL_LINES [ glVertex2d glVertex2d ] do-state ;
48 : line* ( a b -- ) stroke-mode GL_LINES [ [ gl-vertex-2d ] bi@ ] do-state ;
50 : lines ( seq -- ) stroke-mode GL_LINES [ gl-vertices-2d ] do-state ;
52 : line ( seq -- ) lines ;
54 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
56 : line-strip ( seq -- ) stroke-mode GL_LINE_STRIP [ gl-vertices-2d ] do-state ;
58 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
60 : triangles ( seq -- )
61 [ fill-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ]
62 [ stroke-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ] bi ;
64 : triangle ( seq -- ) triangles ;
66 : triangle* ( a b c -- ) 3array triangles ;
68 : triangle** ( x y x y x y -- ) 6 narray 2 group triangles ;
70 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
73 [ fill-mode GL_POLYGON [ gl-vertices-2d ] do-state ]
74 [ stroke-mode GL_POLYGON [ gl-vertices-2d ] do-state ] bi ;
76 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 :: rectangle ( loc dim -- )
80 dim first2 :> ( dx dy )
89 : rectangle* ( x y width height -- ) [ 2array ] 2bi@ rectangle ;
91 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
93 : gl-translate-2d ( pos -- ) first2 0 glTranslated ;
95 : gl-scale-2d ( xy -- ) first2 1 glScaled ;
97 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
99 : gl-ellipse ( center dim -- )
101 [ gl-translate-2d ] [ gl-scale-2d ] bi*
103 dup 0 0.5 20 1 gluDisk
107 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
109 : gl-get-line-width ( -- width )
110 GL_LINE_WIDTH 0 double <ref> tuck glGetDoublev double deref ;
112 : ellipse ( center dim -- )
113 GL_FRONT_AND_BACK GL_FILL glPolygonMode
114 [ stroke-color get gl-color gl-ellipse ]
115 [ fill-color get gl-color gl-get-line-width 2 * dup 2array v- gl-ellipse ] 2bi ;
117 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
119 : circle ( center size -- ) dup 2array ellipse ;
121 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!