Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
is it possible to "setClip()" on a shape? — Gideros Forum

is it possible to "setClip()" on a shape?

piepie Member
edited July 2015 in General questions
I like setClip() :) but I was wondering if there is a way to clip a more specific-custom shape, instead of clipping a "rectangle".

thank you

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Short answer: no that's not possible. Only rectangles.

    Long answer: most probably that's not possible at all with clipping. This stuff probably could be achieved with masking (intersection of on Shape cut off from another Sprite, or something like that), but that's not yet supported :)
  • hgy29hgy29 Maintainer
    Accepted Answer
    Even longer answer:
    - setClip() tells the graphic card to discard pixels outside a rectangular window. This is fast, i.e, no additional processing required.
    - setMask() (not yet implemented but in my TODO list) would require extra computations: first the masking shape would be rendered into a specific buffer called stencil, then actual rendering would check the stencil buffer to selectively discard masked pixels.
  • XmanXman Member
    Looking forward to setMask
  • hgy29hgy29 Maintainer
    Also note that, depending on what you want to achieve, you may already use shaders to perform masking...
  • XmanXman Member
    edited July 2015
    something like do not draw the area where the alpha of the mask image is below the setting threshold.
    Shader is an advanced topic for most of us, maybe a simple setMask api will be better. :))

    Also, if there is a shader example for doing that will be a bonus.
  • hgy29hgy29 Maintainer
    Some quick thought: even without shaders, one can use Shape to show a specific part of a texture.

    See example attached (replace texture with one your files, 512x512)
    zip
    zip
    masking.zip
    3K
  • piepie Member
    Thank you @hgy29, however from my understanding that approach is viable only on textures, or am I missing something?

    I like the idea of setMask, but no need to hurry :D when I asked I was hoping that there already was something similar in the new features from openGL 2.

    Shaders look really interesting, I need to study a bit more because I still can't understand a lot of things in there :)
  • hgy29hgy29 Maintainer
    Yes, this approach will only work on texture, but if not enough then render target can help. No as efficient as the setMask() approach I intend to code some day, however.

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • @pie, you can easily use rendertarget+shape together as @hgy29 recommends, i guess modifying my tutorial/example code is not hard so that it works with any shape:
    http://www.indiedb.com/tutorials/clipping-in-gideros-with-rendertarget

    Likes: pie

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