Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Draw Texture directly - Gideros Forum

Draw Texture directly

Hi everyone,
it has been a while since I used Gideros the last time but I am considering it again for a project I have in mind. Super glad to see it is still alive and apparently venturing into 3d territory which is great. Awesome work!!

My question is regarding 2d however: is it possible to directly draw a texture to any screen coordinates without adding it to the stage? I am not the biggest fan of the Flash API and sometimes I feel it is easier to simply draw directly (similar to Love2d in this regard). So if possible I try to find a way to subvert the scenegraph ;)

Incidentally, if that would be possible, maybe it would convert a few people over from Love as I think in terms of development experience, Gideros is far ahead (and also in terms of deployment targets...). So that would be cool.

Anyway, if it is not possible, that would certainly not be a dealbreaker for me too. Thanks!

Comments

  • MoKaLuxMoKaLux Member
    edited April 20
    Wiki: "Texture class is used to load an image file and holds the data stored in the image file. The Bitmap class inherits from Sprite and wraps a Texture object for on-screen display."
    https://wiki.giderosmobile.com/index.php/Introduction_to_Graphics#Textures_and_Bitmaps

    I don't think it's possible, if you don't add it to the stage you won't see your texture.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • keszeghkeszegh Member
    you can make a rendertarget which would be your 'canvas' and draw everything you want on it. then only this canvas is on stage, nothing else.

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    edited April 20
    Gideros could have a stage:draw() call similar to RenderTarget:draw(). Internally the process would be the same (stage is just the default render target), so very easy to add. If you think it would be useful, then I'll add it

    EDIT: This would work provided that lua is executed after the standard render pass, but before issuing the frame buffer to screen, maybe inside a special callback function triggered at the right point in the draw flow.
  • stetsostetso Member
    Ah, thanks for the pointer to Rendertarget. That certainly seems like what I was looking for. I‘ll play around with it.
  • stetsostetso Member
    hgy29 said:

    Gideros could have a stage:draw() call similar to RenderTarget:draw(). Internally the process would be the same (stage is just the default render target), so very easy to add. If you think it would be useful, then I'll add it

    EDIT: This would work provided that lua is executed after the standard render pass, but before issuing the frame buffer to screen, maybe inside a special callback function triggered at the right point in the draw flow.

    Thank you for the offer to implement it. If I am the only one who thinks that it is useful, maybe let me try with a separate Rendertarget first before putting in the work :) But it is highly appreciated!
  • keszeghkeszegh Member
    with @hgy29 's option there would not be an unnecessary rendertarget, but i also think that it's strange to gideros hierarchy philosophy so it's maybe not that good.
    on the other hand perhaps RenderTarget:drawTexture() could be added with similar parameters as RenderTarget:clear() (somehow similar as Pixel.new accepts color and texture as well when initialized) so that there is no need to create a bitmap to draw a texture on the rendertarget. but again, probably not many people would use this feature.
  • antixantix Member
    Just use a RenderTarget and draw directly into it. Of course you need one Bitmap or Pixel that uses the RenderTarget as it's texture, which would be added to the stage..

    This code has just that...
    local COUNT = 64
    local SIZE = 256
    local LIFE = 60 * 60 -- roughly a minute
     
    local random = math.random
     
    local counter = 0
     
    local canvas = RenderTarget.new(SIZE, SIZE, true, true)
    local region = TextureRegion.new(canvas, 0, 0, application:getContentWidth(), application:getContentHeight())
    local bitmap = Bitmap.new(region)
    stage:addChild(bitmap)
     
    -- brush we will draw to canvas
    local brush = Pixel.new(0xddeeff, 0.20, 1, 1)
     
    -- Make a bunch of random walkers
    local points = {}
    for i = 1, COUNT do
      local point = {
        x = random() * SIZE,
        y = random() * SIZE,
      }
      points[#points + 1] = point
    end
     
    -- walk every frame
    local function onEnterFrame(e)
     
      -- clear on life exceeded
      counter += 1
      if counter >= LIFE then
        counter = 0
        canvas:clear(0, 1)
      end
     
      -- walk
      for i = 1, COUNT do
        local point = points[i]
        local x, y = point.x, point.y
     
        if random() < 0.55 then
          x += 1 -- walk right
          if x > SIZE then
            x -= SIZE
          end
        else
          y += 1 -- walk down
          if y > SIZE then
            y -= SIZE
          end
        end
        point.x, point.y = x, y
     
        brush:setPosition(x, y) -- draw walker on canvas
        canvas:draw(brush)
      end
    end
     
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

    Likes: MoKaLux, stetso

    +1 -1 (+2 / -0 ) Share on Facebook
Sign In or Register to comment.