Sign in to follow this  

blending problems..

This topic is 4594 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 can get the required effect from blending a dark color with my building textures to make it look like nighttime. However I don't understand why it works... eg table 6.1 page 228 of the red book gives the blending fucntion parameters. GL_ONE rgb factor=(1,1,1) alpha =1 Therefore if I want to blend my dark color with my texture - I can assume that the dark color is the source, the texture is the destination. I have not specified an alpha color for each. The blend function is:
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE); ///THIS IS THE BLEND 
glEnable(GL_TEXTURE_2D);
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.1f, 0.1f, 0.1f);
glBindTexture(GL_TEXTURE_2D, buildingTex);


So according to page 226 the resultant color of say the red channel and the alpha after blending would be (1*Rd + 1*Rs,...... 1*Ad+1*As) which you would think would give a totally non transparent building with color channel equal to the combined value of 0.1 + the color channel. Instead it's transparent.
I then tried
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR)

which you would think would take the color of the glColor and combine it with the color of the building tex - but that blend too is transparent !
I don't get it !

So although I can get this to work with other values - the values that I would use from reading the red book don't do as I expect. So can someone explain how to use the values and know what's going on so I can get it right and know why its right? cheers [Edited by - ade-the-heat on May 14, 2005 7:37:36 AM]

Share this post


Link to post
Share on other sites
I don't think you understand what GL_BLEND does. It's used to blend incoming fragments(pixels, if you want it, altough fragments are more correct term) with those that are already in the framebuffer. It doesn't "blend" textures or colors in the same pass. More precisely, it multiplies the source and destination fragments with the factors that you supply in glBlendFunc and then adds them together.


In your case, GL reads the texture color, it modulates it(if your TexEnv is GL_MODULATE) with the primary color. That's the current(source) fragment color. Then it adds that value to the already present(destination) fragment.

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
In your case, GL reads the texture color, it modulates it(if your TexEnv is GL_MODULATE) with the primary color. That's the current(source) fragment color. Then it adds that value to the already present(destination) fragment.


That was my understanding as well,

Share this post


Link to post
Share on other sites
Quote:
Original post by zedzeek
perhaps of interest requires fltk
http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip


Handydandy. cheers zed.

Share this post


Link to post
Share on other sites

This topic is 4594 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this