Jump to content
  • Advertisement
Sign in to follow this  
MylesEvans

OpenGL How to do additive blending between two polygons excluding the clear color?

This topic is 536 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'm trying to blend the colors of two rectangles I've drawn in OpenGL without including the background color (clear color). How do I go about doing this? I have blending enabled/glBlendFunc(GL_ONE,GL_ONE); and all that but when I draw my two transparent rectangles they not only blend their colors together but they also blend the background color. I dont want this. I only want the two rectangles to blend.l

Share this post


Link to post
Share on other sites
Advertisement

So we understand you correctly:

 

- You have two rectangles

- Where they don't overlap, you want them to be opaque so the background doesn't show through

- Where they do overlap, you want them to be the sum of their colors (background also not showing through)

 

Is that correct? Or is there more to it? You say they are "transparent rectangles", yet you don't want the background to show through. That's what's confusing me.

 

Anyway, assuming my assumptions are correct, I think you can do the following (I don't use OpenGL, so I'm not familiar with the exact names for the blending functions, but it should be clear enough):

 

- use separate blending for the alpha and color channels

- ensure the render target has an alpha channel, and that it's been cleared to zero. And that anything you drew previously on it didn't write to the alpha channel (Alpha = SourceAlpha * Zero + DestAlpha * Zero).

- when drawing your rectangles, use:

    Alpha = SourceAlpha * One + DestAlpha * Zero

    Color = SourceColor * One + DestColor * DestAlpha

 

So after drawing one rectangle, the render target should have alpha = 1.0 where the rectangle is. And that basically becomes an indication that you *do* want to blend that part of the background (which has the first rectangle on it) with the next rectangle.

 

I haven't tried it, but I think that should work.

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!