2 USING: kernel namespaces arrays sequences grouping
4 math math.vectors math.geometry.rect
5 opengl.gl opengl.glu opengl generalizations vars
6 combinators.cleave colors ;
10 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12 : do-state ( mode quot -- ) swap glBegin call glEnd ; inline
14 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19 T{ rgba f 0 0 0 1 } stroke-color set-global
20 T{ rgba f 1 1 1 1 } fill-color set-global
22 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 GL_FRONT_AND_BACK GL_FILL glPolygonMode
26 fill-color> gl-color ;
28 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 GL_FRONT_AND_BACK GL_LINE glPolygonMode
32 stroke-color> gl-color ;
34 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36 : gl-vertex-2d ( vertex -- ) first2 glVertex2d ;
38 : gl-vertices-2d ( vertices -- ) [ gl-vertex-2d ] each ;
40 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 : point* ( x y -- ) stroke-mode GL_POINTS [ glVertex2d ] do-state ;
43 : point ( point -- ) stroke-mode GL_POINTS [ gl-vertex-2d ] do-state ;
44 : points ( points -- ) stroke-mode GL_POINTS [ gl-vertices-2d ] do-state ;
46 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 : line** ( x y x y -- )
49 stroke-mode GL_LINES [ glVertex2d glVertex2d ] do-state ;
51 : line* ( a b -- ) stroke-mode GL_LINES [ [ gl-vertex-2d ] bi@ ] do-state ;
53 : lines ( seq -- ) stroke-mode GL_LINES [ gl-vertices-2d ] do-state ;
55 : line ( seq -- ) lines ;
57 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59 : line-strip ( seq -- ) stroke-mode GL_LINE_STRIP [ gl-vertices-2d ] do-state ;
61 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
63 : triangles ( seq -- )
64 [ fill-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ]
65 [ stroke-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ] bi ;
67 : triangle ( seq -- ) triangles ;
69 : triangle* ( a b c -- ) 3array triangles ;
71 : triangle** ( x y x y x y -- ) 6 narray 2 group triangles ;
73 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
76 [ fill-mode GL_POLYGON [ gl-vertices-2d ] do-state ]
77 [ stroke-mode GL_POLYGON [ gl-vertices-2d ] do-state ] bi ;
79 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
81 : rectangle ( loc dim -- )
83 { top-left top-right bottom-right bottom-left }
87 : rectangle* ( x y width height -- ) [ 2array ] 2bi@ rectangle ;
89 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
91 : gl-translate-2d ( pos -- ) first2 0 glTranslated ;
93 : gl-scale-2d ( xy -- ) first2 1 glScaled ;
95 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
97 : gl-ellipse ( center dim -- )
99 [ gl-translate-2d ] [ gl-scale-2d ] bi*
101 dup 0 0.5 20 1 gluDisk
105 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
107 : gl-get-line-width ( -- width )
108 GL_LINE_WIDTH 0 <double> tuck glGetDoublev *double ;
110 : ellipse ( center dim -- )
111 GL_FRONT_AND_BACK GL_FILL glPolygonMode
112 [ stroke-color> gl-color gl-ellipse ]
113 [ fill-color> gl-color gl-get-line-width 2 * dup 2array v- gl-ellipse ] 2bi ;
115 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
117 : circle ( center size -- ) dup 2array ellipse ;
119 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!