         ] do-attribs
     ] do-enabled ; inline
 
+: texture-dim ( texture -- dim )
+    [ dim>> ] [ image>> ] bi 2x?>> [ [ 2.0 / ] map ] when ;
+
 : (draw-textured-rect) ( dim texture -- )
     [ loc>> ]
     [ [ GL_TEXTURE_2D ] dip texture>> glBindTexture ]

TUPLE: multi-texture < disposable grid display-list loc ;

: image-locs ( image-grid -- loc-grid )
    [ first [ dim>> first ] map ] [ [ first dim>> second ] map ] bi
    [ 0 [ + ] accumulate nip ] bi@
    cartesian-product flip ;


    GL_COMPILE [
        [
            [ grid-has-alpha? [ GL_BLEND glDisable ] unless ]
            [ [ [ [ texture-dim ] keep (draw-textured-rect) ] each ] each ]
            [ grid-has-alpha? [ GL_BLEND glEnable ] unless ] tri
            GL_TEXTURE_2D 0 glBindTexture
        ] with-texturing
