PDA

View Full Version : using whiteness for alpha



Neonic
03-15-2011, 01:13 PM
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.

ZbuffeR
03-15-2011, 02:42 PM
Does your fbo have an alpha channel ? Getting only alpha=1 can mean there is none, and default value is always returned.

mhagain
03-15-2011, 03:24 PM
Use a shader and set fragcolor.a equal to texture.r, then stick with your current blendfunc.

Neonic
03-16-2011, 05:36 AM
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:



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.

Nighthawk
03-16-2011, 06:49 AM
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);

Neonic
03-16-2011, 01:17 PM
Alpha test might be enabled. Try glDisable(GL_ALPHA_TEST);

I already tried that. Sorry, I didn't mention it!

Neonic
03-16-2011, 01:40 PM
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!