Drawing a bitmap with DrawTexture, with alpha



  • On 17/08/2015 at 18:49, xxxxxxxx wrote:

    I have a tag that displays a bitmap on the screen, inside the Draw method.
    It draws the bitmap on top of the objects, just like I want.
    However, I would like it to be able to appear with user-defined transparency.
    I already tried using the BaseDraw.SetTransparency and also adjusting the alpha of the image (which is kinda slow). And the image, in fact, becomes dimmer.
    But I still can't see the objects behind it.
    It is as if the image is being properly displayed with transparency but is still clipping the objects behind it.
    Is it possible to have a bitmap displayed in the screen and make it see-through, to see the objects in the editor?



  • On 18/08/2015 at 01:48, xxxxxxxx wrote:

    Hello,

    could you share some code showing how exactly you draw your bitmap?

    Best wishes,
    Sebastian



  • On 18/08/2015 at 04:09, xxxxxxxx wrote:

    Sure. This is how I tried, using BaseDraw.SetTransparency

      
    ...   
    # the bitmap is in the image variable   
    bd.SetMatrix_Screen()   
    bd.DrawLine2D(c4d.Vector(0, 0, 0), c4d.Vector(0, 0, 0))   
    bd.SetDepth(True)   
    trans=int((1.0-tag[PH_OPACITY])*255)   
    bd.SetTransparency(-trans)   
      
    padr=[c4d.Vector(x,y,0),c4d.Vector(x+w,y,0),c4d.Vector(x+w,y+h,0),c4d.Vector(x,y+h,0)]   
    cadr=[c4d.Vector(1,1,1),c4d.Vector(1,1,1),c4d.Vector(1,1,1),c4d.Vector(1,1,1)]   
    nadr=[c4d.Vector(0,0,-1),c4d.Vector(0,0,-1),c4d.Vector(0,0,-1),c4d.Vector(0,0,-1)]   
    uvadr=[c4d.Vector(0,0,0),c4d.Vector(1,0,0),c4d.Vector(1,1,0),c4d.Vector(0,1,0)]   
    bd.DrawTexture(image,padr,cadr,nadr,uvadr,4,c4d.DRAW_ALPHA_NONE,c4d.DRAW_TEXTUREFLAGS_INTERPOLATION_LINEAR)   
    bd.SetDepth(True)   
    

    and this is how I tried, using alpha on the bitmap:

      
    ...   
    # the bitmap is in the image variable   
    bd.SetMatrix_Screen()   
    bd.DrawLine2D(c4d.Vector(0, 0, 0), c4d.Vector(0, 0, 0))   
    bd.SetDepth(True)   
    trans=int((1.0-tag[PH_OPACITY])*255)   
      
    alpha = bitmaps.BaseBitmap()   
    alpha.Init(sx,sy,8)   
      
    new_bitmap = bitmaps.GeClipMap()   
    new_bitmap.InitWithBitmap(image,alpha)   
      
    new_bitmap.BeginDraw()   
      
    for iy in xrange(sy) :   
         for ix in xrange(sx) :   
              r,g,b,a=new_bitmap.GetPixelRGBA(ix,iy)   
              new_bitmap.SetPixelRGBA(ix,iy,r,g,b,trans)   
      
    new_bitmap.EndDraw()   
      
    padr=[c4d.Vector(x,y,0),c4d.Vector(x+w,y,0),c4d.Vector(x+w,y+h,0),c4d.Vector(x,y+h,0)]   
    cadr=[c4d.Vector(1,1,1),c4d.Vector(1,1,1),c4d.Vector(1,1,1),c4d.Vector(1,1,1)]   
    nadr=[c4d.Vector(0,0,-1),c4d.Vector(0,0,-1),c4d.Vector(0,0,-1),c4d.Vector(0,0,-1)]   
    uvadr=[c4d.Vector(0,0,0),c4d.Vector(1,0,0),c4d.Vector(1,1,0),c4d.Vector(0,1,0)]   
    bd.DrawTexture(new_bitmap.GetBitmap(),padr,cadr,nadr,uvadr,4,c4d.DRAW_ALPHA_NORMAL,c4d.DRAW_TEXTUREFLAGS_INTERPOLATION_LINEAR)   
    bd.SetDepth(True)   
    


  • On 18/08/2015 at 06:15, xxxxxxxx wrote:

    Hello,

    to use the alpha stored in the given bitmap you must use the DRAW_ALPHA_FROM_IMAGE flag in DrawTexture().

    Best wishes,
    Sebastian



  • On 18/08/2015 at 06:26, xxxxxxxx wrote:

    I had already tried that and it produces the same effect as using DRAW_ALPHA_NORMAL

    The bitmaps does change opacity but it still clips the objects displayed in the editor. What I would like is to see through it.



  • On 19/08/2015 at 00:03, xxxxxxxx wrote:

    Hello,

    I asked the developers if it is possible to do what you want.

    Best wishes,
    Sebastian



  • On 19/08/2015 at 00:32, xxxxxxxx wrote:

    Thank you, Sebastian

    Rui Batista



  • On 21/08/2015 at 00:32, xxxxxxxx wrote:

    Hello,

    I got feedback from the developers. Indeed, the possibilities of drawing in a TagData's Draw() function are limited. If you want to draw something on top of everything typically a C++ SceneHook should be used. See also "2D viewport drawing using a SceneHook".

    best wishes,
    Sebastian



  • On 21/08/2015 at 04:13, xxxxxxxx wrote:

    Thank you, Sebastian.
    I will take that into account in the future. I will leave this plugin as it is now. It works fine... not perfect, but fine ;-)


Log in to reply