On 11/29/15 7:22 PM, Jon Harper wrote: > There's an image-gadget implementation from images.viewer, maybe you > should start from that and expand to get all the functionnality you > need ? > > IN: scratchpad > "resource:./misc/icons/factor_48...@2x.png" <image-gadget> gadget. > "resource:./misc/icons/factor_48...@2x.png" <image-gadget> "image" open-window > > Jon > > > On Sun, Nov 29, 2015 at 1:37 PM, Sankaranarayanan Viswanathan > <rationalrev...@gmail.com> wrote: >> Hi, >> >> Hi, i'm facing a problem drawing textures in a new window. when I >> create the gadget and add it to the listener using gadget. the image >> shows corretly, when I create the gadget and use open-window, the >> image does not show up on the new window. >> >> Sample code below: >> >> TUPLE: i-gadget < gadget >> image texture ; >> >> : <i-gadget> ( path -- gadget ) >> [ i-gadget new ] dip load-image >>image ; >> >> M: i-gadget pref-dim* >> image>> dim>> [ 20 + ] map ; >> >> M: i-gadget graft* >> dup find-gl-context >> dup image>> { 0 0 } <texture> >>texture drop ; >> >> M: i-gadget ungraft* >> dup find-gl-context >> dup texture>> dispose >> f >>texture drop ; >> >> M: i-gadget draw-gadget* >> [ { 10 10 } ] dip texture>> [ draw-texture ] >> curry with-translation ; >> >> ! In the listener >> >> "vocab:images/sprites/game_drop.png" <i-gadget> gadget. >> >> ! the above works and shows the image in the listener >> >> "vocab:images/sprites/game_drop.png" <i-gadget> "i-gadget" open-window >> >> ! the above opens a new window but the image does not show >> >> What could I be missing? >> >> Thanks, >> Sankar >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk > > ------------------------------------------------------------------------------ >
I see that moving the texture creation code from graft* to draw-gadget* solves the issue. I'm wondering if this is a bug, since the documentation for graft* mentions that resources can be allocated on this method (and to use find-gl-context to ensure the correct GL context is setup before allocating the resources). The modified the code shown below works correctly: M: i-gadget graft* drop ; M: i-gadget draw-gadget* [ { 10 10 } ] dip dup texture>> [ ] [ dup image>> { 0 0 } <texture> >>texture texture>> ] ?if [ draw-texture ] curry with-translation ; image-gadget seems to have been implemented in the same way though (i.e. setting up textures is done on the 1st call into draw-gadget*). Thanks, Sankar ------------------------------------------------------------------------------ _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk