Results 1 to 7 of 7

Thread: using whiteness for alpha

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    25

    using whiteness for alpha

    Hello,

    I'm using a framebuffer object and I'd like this fbo to generate a transparent texture.

    I've tried to render transparent 2D objects to the fbo and then render its texture. However, this doesn't seem to work, only pixels with alpha=1 are rendered to the fbo texture. (unless I use an opaque background)

    So my new plan is now to let the fbo generate a black and white texture(I don't need the colors) and use this texture's whiteness-intensity as an alpha value instead.

    At the moment I use this blending function:

    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)

    This doesn't use the white-intensity for transparency however.
    So my question is: how can I make openGL use the white-intensity instead of the alpha channel for transparency during rendering?

    I'm thinking about solutions like:
    - use a different blending function
    - use a different internal format for the fbo-texture
    - etc.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: using whiteness for alpha

    Does your fbo have an alpha channel ? Getting only alpha=1 can mean there is none, and default value is always returned.

  3. #3
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: using whiteness for alpha

    Use a shader and set fragcolor.a equal to texture.r, then stick with your current blendfunc.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    25

    Re: using whiteness for alpha

    Quote Originally Posted by ZbuffeR
    Does your fbo have an alpha channel ? Getting only alpha=1 can mean there is none, and default value is always returned.
    I build my fbo like this:

    Code :
        glGenFramebuffers(1, &fbo);
     
        glGenTextures(1,&textTexture);
     
     
     
    	glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo);
     
     
     
        glBindTexture(GL_TEXTURE_2D, textTexture);
     
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
     
                    GLsizei(x2-x1), GLsizei(total_textHeight),
     
                     0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,		GL_LINEAR);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,		GL_LINEAR);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,			GL_CLAMP);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,			GL_CLAMP);
     
     
     
    	glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textTexture, 0);
     
     
     
        GLenum status=glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
     
     
     
        glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
     
    	glBindTexture(GL_TEXTURE_2D, 0);

    Also, it's not like I only get alpha=1, it's just that the pixels with alpha<1 are not rendered to the fbo.

  5. #5
    Member Contributor
    Join Date
    Jan 2007
    Posts
    89

    Re: using whiteness for alpha

    Also, it's not like I only get alpha=1, it's just that the pixels with alpha<1 are not rendered to the fbo.
    Alpha test might be enabled. Try glDisable(GL_ALPHA_TEST);

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    25

    Re: using whiteness for alpha

    Quote Originally Posted by Nighthawk
    Alpha test might be enabled. Try glDisable(GL_ALPHA_TEST);
    I already tried that. Sorry, I didn't mention it!

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    25

    Re: using whiteness for alpha

    Quote Originally Posted by mhagain
    Use a shader and set fragcolor.a equal to texture.r, then stick with your current blendfunc.
    Yes! This sounds like it can work. Thank you!

Similar Threads

  1. Replies: 1
    Last Post: 08-03-2012, 12:13 AM
  2. Replies: 3
    Last Post: 06-16-2011, 12:51 PM
  3. alpha blending without modifying destination alpha
    By GordAllott in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-21-2009, 04:15 AM
  4. Source Alpha Blending without an Alpha Buffer
    By niallm in forum OpenGL ES
    Replies: 1
    Last Post: 06-18-2009, 02:51 AM
  5. Alpha to coverage vs alpha test
    By imported_Groovounet in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 01-21-2008, 12:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean