]> gitweb.factorcode.org Git - factor.git/commitdiff
extra/: more uses of the do-state combinator
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 27 Jan 2018 19:07:00 +0000 (20:07 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 27 Jan 2018 21:44:26 +0000 (22:44 +0100)
extra/gtk-samples/opengl/opengl.factor
extra/math/splines/viewer/viewer.factor
extra/maze/maze.factor
extra/processing/shapes/shapes.factor

index 6e2a090fecde518c43aa34380bd4cd7ee4341252..66653a05eace3695b9be796dd21d8e39b6a28128 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2010 Anton Gorenko.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.strings gdk.gl.ffi gobject.ffi gtk.ffi gtk.gl.ffi
-io.encodings.utf8 kernel locals opengl.gl ;
+io.encodings.utf8 kernel locals opengl.demo-support opengl.gl ;
 IN: gtk-samples.opengl
 
 ! This sample is based on
@@ -25,14 +25,14 @@ IN: gtk-samples.opengl
     [
         GL_COLOR_BUFFER_BIT glClear
 
-        GL_TRIANGLES glBegin
-        1.0 0.0 0.0 glColor3f
-        0 1 glVertex2i
-        0.0 1.0 0.0 glColor3f
-        -1 -1 glVertex2i
-        0.0 0.0 1.0 glColor3f
-        1 -1 glVertex2i
-        glEnd
+        GL_TRIANGLES [
+            1.0 0.0 0.0 glColor3f
+            0 1 glVertex2i
+            0.0 1.0 0.0 glColor3f
+            -1 -1 glVertex2i
+            0.0 0.0 1.0 glColor3f
+            1 -1 glVertex2i
+        ] do-state
 
         gl-drawable gdk_gl_drawable_is_double_buffered 1 =
         [ gl-drawable gdk_gl_drawable_swap_buffers ]
index 59c347d740f17f6e41da46bdb1e0b7c5369da628..1084510f2b95fcd4966daeb7ca59da052d5b1b8a 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2010 Erik Charlebois.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel locals math math.order math.polynomials
-math.splines opengl.gl sequences ui.gadgets ui.gadgets.panes ui.render
-arrays ;
+math.splines opengl.demo-support opengl.gl sequences ui.gadgets
+ui.gadgets.panes ui.render arrays ;
 IN: math.splines.viewer
 
 <PRIVATE
@@ -33,11 +33,11 @@ M:: spline-gadget draw-gadget* ( gadget -- )
         [ second y-min - y-max y-min - / gadget spline-dim>> second * ] bi 2array
     ] map :> pts
 
-    GL_LINE_STRIP glBegin
-    pts [
-        first2 neg gadget spline-dim>> second + glVertex2f
-    ] each
-    glEnd ;
+    GL_LINE_STRIP [
+        pts [
+            first2 neg gadget spline-dim>> second + glVertex2f
+        ] each ]
+    do-state ;
 
 :: <spline-gadget> ( polynomials dim steps -- gadget )
     spline-gadget new
index 0e4af964d3555e65c5d908846daa299fa444adc1..f682d4600d8dd86748737662626ae785cbc396bd 100644 (file)
@@ -1,7 +1,7 @@
 ! From http://www.ffconsultancy.com/ocaml/maze/index.html
 USING: accessors arrays fry kernel math math.order math.vectors
-namespaces opengl.gl random sequences ui ui.gadgets
-ui.gadgets.canvas ui.render ;
+namespaces opengl.demo-support opengl.gl random sequences ui
+ui.gadgets ui.gadgets.canvas ui.render ;
 IN: maze
 
 CONSTANT: line-width 8
@@ -25,7 +25,7 @@ SYMBOL: visited
 : (draw-maze) ( cell -- )
     dup vertex
     glEnd
-    GL_POINTS glBegin dup vertex glEnd
+    GL_POINTS [ dup vertex ] do-state
     GL_LINE_STRIP glBegin
     dup vertex
     dup visit
@@ -42,9 +42,9 @@ SYMBOL: visited
     line-width 2 - glPointSize
     1.0 1.0 1.0 1.0 glColor4d
     dup '[ _ t <array> ] replicate visited set
-    GL_LINE_STRIP glBegin
-    { 0 0 } dup vertex (draw-maze)
-    glEnd ;
+    GL_LINE_STRIP [
+        { 0 0 } dup vertex (draw-maze)
+    ] do-state ;
 
 TUPLE: maze < canvas ;
 
index e4e1dd44b824b049062180d453b2a0e5481837a4..e11871e5e205c31829ff142de959f0c0f3400405 100644 (file)
@@ -1,10 +1,8 @@
 USING: alien.c-types alien.data arrays colors.constants grouping
-kernel locals math math.vectors namespaces opengl opengl.gl
-opengl.glu sequences sequences.generalizations shuffle ;
+kernel locals math math.vectors namespaces opengl opengl.demo-support
+opengl.gl opengl.glu sequences sequences.generalizations shuffle ;
 IN: processing.shapes
 
-: do-state ( mode quot -- ) swap glBegin call glEnd ; inline
-
 SYMBOL: fill-color
 SYMBOL: stroke-color