2 USING: kernel namespaces arrays sequences grouping
4 math math.vectors math.geometry.rect
5 opengl.gl opengl.glu opengl.demo-support opengl generalizations vars
6 combinators.cleave colors ;
10 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 T{ rgba f 0 0 0 1 } stroke-color set-global
16 T{ rgba f 1 1 1 1 } fill-color set-global
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21 GL_FRONT_AND_BACK GL_FILL glPolygonMode
22 fill-color> gl-color ;
24 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 GL_FRONT_AND_BACK GL_LINE glPolygonMode
28 stroke-color> gl-color ;
30 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32 : gl-vertex-2d ( vertex -- ) first2 glVertex2d ;
34 : gl-vertices-2d ( vertices -- ) [ gl-vertex-2d ] each ;
36 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38 : point* ( x y -- ) stroke-mode GL_POINTS [ glVertex2d ] do-state ;
39 : point ( point -- ) stroke-mode GL_POINTS [ gl-vertex-2d ] do-state ;
40 : points ( points -- ) stroke-mode GL_POINTS [ gl-vertices-2d ] do-state ;
42 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
44 : line** ( x y x y -- )
45 stroke-mode GL_LINES [ glVertex2d glVertex2d ] do-state ;
47 : line* ( a b -- ) stroke-mode GL_LINES [ [ gl-vertex-2d ] bi@ ] do-state ;
49 : lines ( seq -- ) stroke-mode GL_LINES [ gl-vertices-2d ] do-state ;
51 : line ( seq -- ) lines ;
53 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
55 : line-strip ( seq -- ) stroke-mode GL_LINE_STRIP [ gl-vertices-2d ] do-state ;
57 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59 : triangles ( seq -- )
60 [ fill-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ]
61 [ stroke-mode GL_TRIANGLES [ gl-vertices-2d ] do-state ] bi ;
63 : triangle ( seq -- ) triangles ;
65 : triangle* ( a b c -- ) 3array triangles ;
67 : triangle** ( x y x y x y -- ) 6 narray 2 group triangles ;
69 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 [ fill-mode GL_POLYGON [ gl-vertices-2d ] do-state ]
73 [ stroke-mode GL_POLYGON [ gl-vertices-2d ] do-state ] bi ;
75 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 : rectangle ( loc dim -- )
79 { top-left top-right bottom-right bottom-left }
83 : rectangle* ( x y width height -- ) [ 2array ] 2bi@ rectangle ;
85 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87 : gl-translate-2d ( pos -- ) first2 0 glTranslated ;
89 : gl-scale-2d ( xy -- ) first2 1 glScaled ;
91 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
93 : gl-ellipse ( center dim -- )
95 [ gl-translate-2d ] [ gl-scale-2d ] bi*
97 dup 0 0.5 20 1 gluDisk
101 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
103 : gl-get-line-width ( -- width )
104 GL_LINE_WIDTH 0 <double> tuck glGetDoublev *double ;
106 : ellipse ( center dim -- )
107 GL_FRONT_AND_BACK GL_FILL glPolygonMode
108 [ stroke-color> gl-color gl-ellipse ]
109 [ fill-color> gl-color gl-get-line-width 2 * dup 2array v- gl-ellipse ] 2bi ;
111 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
113 : circle ( center size -- ) dup 2array ellipse ;
115 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!