Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

soconne

OpenGL OpenGL Blending Math

This topic is 5224 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 implement my own blending routines to take two images and create a 3rd that is a blend of the two. The blend parameters are specified by the user. So far all I've managed to get to work correctly is the following blend situations: glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR); glBlendFunc(GL_ONE, GL_ONE); But no other ones work correctly. Can anybody tell me what's wrong with my code? CODE [edited by - oconnellseanm on June 2, 2004 4:34:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
You're mixing up source and destination at several places, and sometimes you assign the factor only to newc0 and newc1, and sometimes you assign the factor and the color multiplied.

Try something like this instead, where you separate factors and colors, and combine them in the end instead.

src_color = src[j]/255;
dst_color = dst[j]/255;

switch(blend0)
{
case GL_ZERO: src_factor = 0;
case GL_ONE: src_factor = 1;
case GL_SRC_COLOR: src_factor = src_color;
case GL_ONE_MINUS_SRC_COLOR: src_factor = 1-dst_color;
....
}

switch(blend1)
{
case GL_ZERO: dst_factor = 0;
case GL_ONE: dst_factor = 1;
....
}

val = (src_color*src_factor + dst_color*dst_factor) / 255;
...


[edited by - Brother Bob on June 2, 2004 4:49:08 PM]

Share this post


Link to post
Share on other sites

  • 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!