Jump to content
  • Advertisement
Sign in to follow this  

Using Blending for Bitmap

This topic is 2864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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!!!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!