Jump to content
  • Advertisement
Sign in to follow this  
Paprica

OpenGL Can't understand the logic behind glBlendFunc()

This topic is 2256 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

I've been reading this chapter about blending in OpenGL:
http://fly.cc.fer.hr.../chapter07.html

Can anyone explain me (in a better way than in the article) the next blending formula, and how I have to use it in order to achieve my wanted results?
(RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)

A link to a better article about OpenGL blending would be appreciated as well. rolleyes.gif Edited by Paprica

Share this post


Link to post
Share on other sites
Advertisement
That is pretty confusing.
That would be additive blending with GL_SRC_ALPHA, GL_DST_ALPHA as the glBLendFunc.

The equation written nicely would be
(R,G,B)*SRC_ALPHA + (R,G,B)*DST_ALPHA
source dest

If the incoming pixel and current pixel on screen have an alpha of 1, then the two pixels getting completely added (R+R, G+G, B+B).
Most useful glBlendFunc is GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA. As incoming source alpha is more opaque, the current pixel gets covered up.

Share this post


Link to post
Share on other sites
There isn't anything to learn.
glEnable(GL_BLEND);
glBlendFunc(..........,.........);
//draw stuff
glDisable(GL_BLEND);

optionally glBlendEquation() but I still have yet to use that for anything other than default.

It comes down to what you want to do with glBlendFunc(), If you want a cloud that has alpha, the GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA. If you want a glowing effect, GL_ONE, GL_ONE works. Thats pretty much it.

If your cloud is glColor4f(1,1,1,.7), then
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
will make the pixel drawn .7*incoming pixel + (1.0-.7) = .3*current pixel. = mostly cloud.
if the cloud is not very dense, then

If your cloud is glColor4f(1,1,1,.2), then
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
will make the pixel drawn .2*incoming pixel + (1.0-.2) = .8*current pixel. = not much cloud showing. Edited by dpadam450

Share this post


Link to post
Share on other sites
What's a glowing effect? Will I ever need something other than GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA if I want to draw just tree / grass textures with transparency? (not sure if it's even related to the blending function, but still asking) Edited by Paprica

Share this post


Link to post
Share on other sites
Nope. you may want to do GL_ALPHA_TEST instead of blending, or GL_ALPHA_TEST with blending. No point in blending pixels that have a 0 alpha so they get discarded by the alpha test.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!