Index: gl-helper.fs ================================================================== --- gl-helper.fs +++ gl-helper.fs @@ -207,12 +207,13 @@ 2r> 2swap ; Variable $attrib : >bindattrib ( xt program -- ) 0 { prog idx } shader>string - BEGIN s" attribute " >attrib extract-name dup WHILE $attrib $! - prog idx $attrib $@ over + 0 swap c! glBindAttribLocation + BEGIN s" attribute " >attrib extract-name dup WHILE + $attrib $! 0 $attrib c$+! + prog idx $attrib $@ drop glBindAttribLocation idx 1+ to idx REPEAT 2drop 2drop ; : >univattrib ( xt program -- ) { prog } shader>string @@ -406,16 +407,19 @@ top bottom f+ top bottom f- f/ sf!+ near far f+ near far f- f/ sf!+ -1e sf!+ sfloat+ sfloat+ near far f* f2* near far f- f/ sf!+ 0e sf!+ drop ; +: ap-set ( -- ) + ap-matrix MVPMatrix set-matrix + ap-matrix MVMatrix set-matrix ; + : >ap ( near far scale -- ) f2* 1/f { f: scale } scale dpy-w @ fm* fdup fnegate fswap scale dpy-h @ fm* fdup fnegate fswap >ortho \ cr ap-matrix .matrix - ap-matrix MVPMatrix set-matrix - ap-matrix MVMatrix set-matrix ; + ap-set ; : >apxy ( xoff yoff -- ) y-apos sf! x-apos sf! ; \ textures Create white-texture \ aabbggrr @@ -510,26 +514,10 @@ Ambient 1 ambient% glUniform1fv LightPos 0.0e 0.0e -0.3e glUniform3f z-bias set-color+ .01e 100e dpy-w @ dpy-h @ min s>f f2/ 100 fm* >ap ; -: 2d-vertex ( index addr -- ) >r - dup 2 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: 3d-vertex ( index addr -- ) >r - dup 3 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: 4d-vertex ( index addr -- ) >r - dup 4 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: rgba-vertex ( index addr -- ) >r - dup 4 GL_UNSIGNED_BYTE GL_TRUE 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - \ glDrawElements helper $8 cells buffer: gl-buffers : buf@ ( n -- buf ) cells gl-buffers + @ ; : bind-buf ( type n -- ) buf@ glBindBuffer ; Index: gl-sample.fs ================================================================== --- gl-sample.fs +++ gl-sample.fs @@ -1,10 +1,10 @@ \ opengl example require gl-helper.fs -also opengl +also opengl also [IFDEF] android android [THEN] tex: ascii-tex : load-textures ( -- ) ascii-tex s" ascii.png" load-texture wrap mipmap ; @@ -37,21 +37,10 @@ : normals >v 3 0 DO 0e 0e -1e n>xyz v+ LOOP o> ; Variable new-config - -[IFDEF] android -also android - -:noname defers window-init - ['] VertexShader ['] FragmentShader create-program to program - program init load-textures ; IS window-init - -:noname new-config on ; is config-changed -[THEN] - FVariable touch -100e touch f! FVariable motion 0.01e motion f! : draw-tri-angle ( f -- ) 0.01e 0.02e 0.15e 1.0e glClearColor @@ -66,13 +55,10 @@ ascii-tex GL_TRIANGLES draw-elements sync ; : draw-tri { f: angle -- angle' } - new-config @ IF - dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF new-config off THEN - THEN angle draw-tri-angle >looper *input >r r@ IF r@ action @ abs 1 <> IF \ ." Touch at " r@ x0 ? r@ y0 ? cr ADDED gl-simple.fs Index: gl-simple.fs ================================================================== --- /dev/null +++ gl-simple.fs @@ -0,0 +1,25 @@ +\ simple opengl test + +[defined] init-opengl 0= constant standalone +require gl-helper.fs +also opengl +also [IFDEF] android android [THEN] +standalone [if] init-opengl buffer-init [then] + +: simple-init ( -- ) + ['] VertexShader ['] FragmentShader create-program to program + program init 0e >y-pos + 1e 0e 0e 1e glClearColor ; + +: draw ( -- ) none-tex + v0 >v + -1e -1e >xy $FFFFFFFF rgba>c n> v+ + 1e -1e >xy $FFFFFFFF rgba>c n> v+ + 0e 1e >xy $FFFFFFFF rgba>c n> v+ v> + i0 0 i, 1 i, 2 i, + GL_TRIANGLES draw-elements ; + +: simple ( -- ) simple-init + 1 level# +! begin clear draw sync >looper level# @ 0= until ; + +simple Index: gl-terminal.fs ================================================================== --- gl-terminal.fs +++ gl-terminal.fs @@ -96,12 +96,12 @@ $ffbf4040 l, \ dimm Blue $ffbf40bf l, \ dimm Magenta $ffbfbf40 l, \ dimm Cyan $ffbfbfbf l, \ dimm White -: term-load-textures ( -- ) - chars-tex s" ascii.png" load-texture 2drop linear +: term-load-textures ( addr u -- ) + chars-tex load-texture 2drop linear GL_TEXTURE2 glActiveTexture color-tex color-matrix $10 1 rgba-map nearest GL_TEXTURE0 glActiveTexture ; Variable color-index @@ -312,16 +312,17 @@ default-out op-vector ! \ initialize : term-init ( -- ) - clazz >o hideProgress o> + [IFDEF] clazz clazz >o hideProgress o> [THEN] >screen-orientation create-terminal-program to terminal-program - terminal-program terminal-init term-load-textures form-chooser + terminal-program terminal-init + s" ascii.png" term-load-textures form-chooser unit-matrix MVPMatrix set-matrix ; :noname defers window-init term-init config-changer ; IS window-init window-init previous previous \ remove opengl from search order Index: gles2/gl-helper.fs ================================================================== --- gles2/gl-helper.fs +++ gles2/gl-helper.fs @@ -207,12 +207,13 @@ 2r> 2swap ; Variable $attrib : >bindattrib ( xt program -- ) 0 { prog idx } shader>string - BEGIN s" attribute " >attrib extract-name dup WHILE $attrib $! - prog idx $attrib $@ over + 0 swap c! glBindAttribLocation + BEGIN s" attribute " >attrib extract-name dup WHILE + $attrib $! 0 $attrib c$+! + prog idx $attrib $@ drop glBindAttribLocation idx 1+ to idx REPEAT 2drop 2drop ; : >univattrib ( xt program -- ) { prog } shader>string @@ -406,16 +407,19 @@ top bottom f+ top bottom f- f/ sf!+ near far f+ near far f- f/ sf!+ -1e sf!+ sfloat+ sfloat+ near far f* f2* near far f- f/ sf!+ 0e sf!+ drop ; +: ap-set ( -- ) + ap-matrix MVPMatrix set-matrix + ap-matrix MVMatrix set-matrix ; + : >ap ( near far scale -- ) f2* 1/f { f: scale } scale dpy-w @ fm* fdup fnegate fswap scale dpy-h @ fm* fdup fnegate fswap >ortho \ cr ap-matrix .matrix - ap-matrix MVPMatrix set-matrix - ap-matrix MVMatrix set-matrix ; + ap-set ; : >apxy ( xoff yoff -- ) y-apos sf! x-apos sf! ; \ textures Create white-texture \ aabbggrr @@ -510,26 +514,10 @@ Ambient 1 ambient% glUniform1fv LightPos 0.0e 0.0e -0.3e glUniform3f z-bias set-color+ .01e 100e dpy-w @ dpy-h @ min s>f f2/ 100 fm* >ap ; -: 2d-vertex ( index addr -- ) >r - dup 2 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: 3d-vertex ( index addr -- ) >r - dup 3 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: 4d-vertex ( index addr -- ) >r - dup 4 GL_FLOAT 0 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - -: rgba-vertex ( index addr -- ) >r - dup 4 GL_UNSIGNED_BYTE GL_TRUE 0 r> glVertexAttribPointer - glEnableVertexAttribArray ; - \ glDrawElements helper $8 cells buffer: gl-buffers : buf@ ( n -- buf ) cells gl-buffers + @ ; : bind-buf ( type n -- ) buf@ glBindBuffer ; Index: gles2/gl-sample.fs ================================================================== --- gles2/gl-sample.fs +++ gles2/gl-sample.fs @@ -1,10 +1,10 @@ \ opengl example require gl-helper.fs -also opengl +also opengl also [IFDEF] android android [THEN] tex: ascii-tex : load-textures ( -- ) ascii-tex s" ascii.png" load-texture wrap mipmap ; @@ -37,21 +37,10 @@ : normals >v 3 0 DO 0e 0e -1e n>xyz v+ LOOP o> ; Variable new-config - -[IFDEF] android -also android - -:noname defers window-init - ['] VertexShader ['] FragmentShader create-program to program - program init load-textures ; IS window-init - -:noname new-config on ; is config-changed -[THEN] - FVariable touch -100e touch f! FVariable motion 0.01e motion f! : draw-tri-angle ( f -- ) 0.01e 0.02e 0.15e 1.0e glClearColor @@ -66,13 +55,10 @@ ascii-tex GL_TRIANGLES draw-elements sync ; : draw-tri { f: angle -- angle' } - new-config @ IF - dpy-w @ dpy-h @ getwh dpy-w @ dpy-h @ d<> IF new-config off THEN - THEN angle draw-tri-angle >looper *input >r r@ IF r@ action @ abs 1 <> IF \ ." Touch at " r@ x0 ? r@ y0 ? cr ADDED gles2/gl-simple.fs Index: gles2/gl-simple.fs ================================================================== --- /dev/null +++ gles2/gl-simple.fs @@ -0,0 +1,25 @@ +\ simple opengl test + +[defined] init-opengl 0= constant standalone +require gl-helper.fs +also opengl +also [IFDEF] android android [THEN] +standalone [if] init-opengl buffer-init [then] + +: simple-init ( -- ) + ['] VertexShader ['] FragmentShader create-program to program + program init 0e >y-pos + 1e 0e 0e 1e glClearColor ; + +: draw ( -- ) none-tex + v0 >v + -1e -1e >xy $FFFFFFFF rgba>c n> v+ + 1e -1e >xy $FFFFFFFF rgba>c n> v+ + 0e 1e >xy $FFFFFFFF rgba>c n> v+ v> + i0 0 i, 1 i, 2 i, + GL_TRIANGLES draw-elements ; + +: simple ( -- ) simple-init + 1 level# +! begin clear draw sync >looper level# @ 0= until ; + +simple Index: gles2/gl-terminal.fs ================================================================== --- gles2/gl-terminal.fs +++ gles2/gl-terminal.fs @@ -96,12 +96,12 @@ $ffbf4040 l, \ dimm Blue $ffbf40bf l, \ dimm Magenta $ffbfbf40 l, \ dimm Cyan $ffbfbfbf l, \ dimm White -: term-load-textures ( -- ) - chars-tex s" ascii.png" load-texture 2drop linear +: term-load-textures ( addr u -- ) + chars-tex load-texture 2drop linear GL_TEXTURE2 glActiveTexture color-tex color-matrix $10 1 rgba-map nearest GL_TEXTURE0 glActiveTexture ; Variable color-index @@ -312,16 +312,17 @@ default-out op-vector ! \ initialize : term-init ( -- ) - clazz >o hideProgress o> + [IFDEF] clazz clazz >o hideProgress o> [THEN] >screen-orientation create-terminal-program to terminal-program - terminal-program terminal-init term-load-textures form-chooser + terminal-program terminal-init + s" ascii.png" term-load-textures form-chooser unit-matrix MVPMatrix set-matrix ; :noname defers window-init term-init config-changer ; IS window-init window-init previous previous \ remove opengl from search order