Results 1 to 3 of 3

Thread: TBGL-Drawing Alpha 2D

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    TBGL-Drawing Alpha 2D

    I want to create some boxes in front of my TBGL-Screen where some numbers shall be displayed on. I have set
    TBGL_UseAlphaTest(%TRUE) 
    TBGL_AlphaFunc(%TBGL_GREATER, 0.5)
    
    and use a TBGL_Color with a little more than 160 alpha to draw the box translucent. But it is full opaque till down to alpha 128
    If I use 127 the box appears totally transparent (is invisible)
    How can I setup to draw the box to appear translucent?

    What have I overseen this time?
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Hi Rene,

    you were close

    There are two alpha related operations in TBGL - alpha testing and alpha blending.

    Alpha testing does what you experienced. It tests the alpha of incoming fragment (pixel) and based on its value it makes it solid or invisible. Nothing in between.

    Alpha blending on the other side allows to use the full scale of transparency, and does what you need - based on alpha value, it blends the incoming fragment color with existing, creating the nice illusion of transparency.

    To enable alpha blending, you need to enable blending as a such, and setup the blending function accordingly. Here little sample:
    TBGL_UseBlend TRUE
    TBGL_BlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA
    
      ' -- Render the transparent stuff here
    
    Or, maybe better you could use the state preserving approach to avoid state leaks:
    TBGL_PushBlendFunc %GL_SRC_ALPHA, %GL_ONE_MINUS_SRC_ALPHA
      TBGL_PushState %TBGL_BLEND
      
      ' -- Render the transparent stuff here
      
      TBGL_PopState
    TBGL_PopBlendFunc
    

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Yeah, that's cool
    Works better than expected, I see a whole lot of new possibilities now. Great!
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Ordering 2D-Drawing - curious...
    By ReneMiner in forum TBGL General
    Replies: 5
    Last Post: 13-11-2012, 09:52
  2. Cool :-) 3D drawing
    By martin in forum Technology
    Replies: 3
    Last Post: 15-08-2009, 12:58
  3. How is drawing a sprite done ?
    By efly2020 in forum TBGL General
    Replies: 16
    Last Post: 23-01-2009, 18:58
  4. TAB Alpha Release 37
    By catventure in forum T.A.B. (ThinBasic Adventure Builder)
    Replies: 28
    Last Post: 01-08-2008, 05:40
  5. TAB Alpha Release 20
    By catventure in forum T.A.B. (ThinBasic Adventure Builder)
    Replies: 18
    Last Post: 22-01-2007, 20:39

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •