Using Blending for Bitmap

Started by
3 comments, last by stevenie 13 years, 9 months ago
Hello everyone,

I'm working on Nehe's #09 tutorial.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=09

In the tutorial, he uses a bitmap with black background for texture. With the blending function:

glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_BLEND);

Somehow the black background is removed from the texture. I'm now sure how this works. Any helps?


Thanks!

Steven
Advertisement
The blending equation is as follows

src*srcFactor + dst*dstFactor = output

In your case srcFactor=source fragment's alpha(the little textured quad with that star like texture) and dstFactor is GL_ONE. The equation becomes

src*alpha + dst*1 = output

src = the star shaped image
dst = framebuffer

The black pixels from the star shaped texture are removed because their corresponding alpha is zero. The image becomes brighter and brighter because this alpha function adds the results to the framebuffer, which does not contain a factor in the equation(it's factor is 1).
Hi Deliverance, Thanks for your reply.

Quote:Original post by Deliverance

The black pixels from the star shaped texture are removed because their corresponding alpha is zero.


Okay for the bitmap, there's no alpha channel right? so all the color pixels should have zero channel. Isn't that correct?

Thanks!

Steven
Quote:Original post by stevenie
Hi Deliverance, Thanks for your reply.

Quote:Original post by Deliverance

The black pixels from the star shaped texture are removed because their corresponding alpha is zero.


Okay for the bitmap, there's no alpha channel right? so all the color pixels should have zero channel. Isn't that correct?

Thanks!

Steven


Okay, i notice there's an eight bit bitmap there. So here's what happens, instead of having a different alpha value per pixel, we have a constant value for the entire quad textured with the star shaped texture.

The black color dissapears because of this:

(0,0,0,0) * constantAlpha + dst*1 = dst, that means that the black pixels don't change the framebuffer.

Hope this makes sense!
Quote:Original post by Deliverance
Quote:Original post by stevenie
Hi Deliverance, Thanks for your reply.

Quote:Original post by Deliverance

The black pixels from the star shaped texture are removed because their corresponding alpha is zero.


Okay for the bitmap, there's no alpha channel right? so all the color pixels should have zero channel. Isn't that correct?

Thanks!

Steven


Okay, i notice there's an eight bit bitmap there. So here's what happens, instead of having a different alpha value per pixel, we have a constant value for the entire quad textured with the star shaped texture.

The black color dissapears because of this:

(0,0,0,0) * constantAlpha + dst*1 = dst, that means that the black pixels don't change the framebuffer.

Hope this makes sense!


Yes, Thanks!!!!

This topic is closed to new replies.

Advertisement