USING: accessors assocs cache colors.constants destructors fry kernel
opengl opengl.gl combinators images images.tesselation grouping
specialized-arrays.float locals sequences math math.vectors
-math.matrices generalizations fry columns ;
+math.matrices generalizations fry columns arrays ;
IN: opengl.textures
: gen-texture ( -- id ) [ glGenTextures ] (gen-gl-object) ;
<PRIVATE
-TUPLE: single-texture loc dim texture-coords texture display-list disposed ;
+TUPLE: single-texture image loc dim texture-coords texture display-list disposed ;
: repeat-last ( seq n -- seq' )
over peek pad-tail concat ;
tri * group ; inline
: power-of-2-image ( image -- image )
- dup dim>> [ 0 = ] all? [
+ dup dim>> [ [ 0 = ] [ power-of-2? ] bi or ] all? [
clone dup
[ image-rows ]
[ dim>> [ next-power-of-2 ] map ]
: draw-textured-rect ( dim texture -- )
[
- (draw-textured-rect)
- GL_TEXTURE_2D 0 glBindTexture
+ [ image>> has-alpha? [ GL_BLEND glDisable ] unless ]
+ [ (draw-textured-rect) GL_TEXTURE_2D 0 glBindTexture ]
+ [ image>> has-alpha? [ GL_BLEND glEnable ] unless ]
+ tri
] with-texturing ;
-: texture-coords ( dim -- coords )
- [ dup next-power-of-2 /f ] map
- { { 0 0 } { 1 0 } { 1 1 } { 0 1 } } [ v* ] with map
+: texture-coords ( texture -- coords )
+ [
+ [ dim>> ] [ image>> dim>> ] bi v/
+ { { 0 0 } { 1 0 } { 1 1 } { 0 1 } }
+ [ v* ] with map
+ ] keep
+ image>> upside-down?>> [ [ first2 1 swap - 2array ] map ] when
float-array{ } join ;
: make-texture-display-list ( texture -- dlist )
GL_COMPILE [ [ dim>> ] keep draw-textured-rect ] make-dlist ;
-: <single-texture> ( image loc -- texture )
- single-texture new swap >>loc
- swap
- [ dim>> >>dim ] keep
- [ dim>> product 0 = ] keep '[
- _
- [ dim>> texture-coords >>texture-coords ]
- [ power-of-2-image make-texture >>texture ] bi
+: <single-texture> ( image loc dim -- texture )
+ [ power-of-2-image ] 2dip
+ single-texture new swap >>dim swap >>loc swap >>image
+ dup image>> dim>> product 0 = [
+ dup texture-coords >>texture-coords
+ dup image>> make-texture >>texture
dup make-texture-display-list >>display-list
] unless ;
: <texture-grid> ( image-grid loc -- grid )
[ dup image-locs ] dip
- '[ [ _ v+ <single-texture> |dispose ] 2map ] 2map ;
+ '[ [ _ v+ over dim>> <single-texture> |dispose ] 2map ] 2map ;
: draw-textured-grid ( grid -- )
[ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ;
+: grid-has-alpha? ( grid -- ? )
+ first first image>> has-alpha? ;
+
: make-textured-grid-display-list ( grid -- dlist )
GL_COMPILE [
[
- [
- [
- [ dim>> ] keep (draw-textured-rect)
- ] each
- ] each
+ [ grid-has-alpha? [ GL_BLEND glDisable ] unless ]
+ [ [ [ [ dim>> ] keep (draw-textured-rect) ] each ] each ]
+ [ grid-has-alpha? [ GL_BLEND glEnable ] unless ] tri
GL_TEXTURE_2D 0 glBindTexture
] with-texturing
] make-dlist ;
M: multi-texture dispose* grid>> [ [ dispose ] each ] each ;
-CONSTANT: max-texture-size { 256 256 }
+CONSTANT: max-texture-size { 512 512 }
PRIVATE>
-: <texture> ( image loc -- texture )
- over dim>> max-texture-size [ <= ] 2all?
+: small-texture? ( dim -- ? )
+ max-texture-size [ <= ] 2all? ;
+
+: <texture> ( image loc dim -- texture )
+ pick dim>> small-texture?
[ <single-texture> ]
- [ [ max-texture-size tesselate ] dip <multi-texture> ] if ;
\ No newline at end of file
+ [ drop [ max-texture-size tesselate ] dip <multi-texture> ] if ;
\ No newline at end of file
! Copyright (C) 2009 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
-USING: accessors assocs cache kernel math.vectors sequences\r
+USING: accessors assocs cache kernel math math.vectors sequences fonts\r
namespaces opengl.textures ui.text ui.text.private ui.gadgets.worlds \r
windows.uniscribe ;\r
IN: ui.text.uniscribe\r
\r
: rendered-script-string ( font string -- texture )\r
world get world-text-handle\r
- [ cached-script-string [ image>> ] [ text-position vneg ] bi <texture> ]\r
+ [ cached-script-string [ image>> { 0 0 } ] [ size>> ] bi <texture> ]\r
2cache ;\r
\r
M: uniscribe-renderer draw-string ( font string -- )\r
- [ drop ] [ rendered-script-string draw-texture ] if-empty ;\r
+ dup dup selection? [ string>> ] when empty?\r
+ [ 2drop ] [ rendered-script-string draw-texture ] if ;\r
\r
M: uniscribe-renderer x>offset ( x font string -- n )\r
[ 2drop 0 ] [\r
- cached-script-string x>line-offset drop\r
+ cached-script-string x>line-offset 0 = [ 1+ ] unless\r
] if-empty ;\r
\r
M: uniscribe-renderer offset>x ( n font string -- x )\r