blending problems..

Started by
4 comments, last by ade-the-heat 18 years, 11 months ago
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]
Advertisement
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.

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,
perhaps of interest requires fltk
http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip
Quote:Original post by zedzeek
perhaps of interest requires fltk
http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip


Handydandy. cheers zed.

[size="1"]
Quote:Original post by zedzeek
perhaps of interest requires fltk
http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip


fab thanks

This topic is closed to new replies.

Advertisement