Blending?

I have 2 textures loaded.
stars.bmp
clouds.bmp

I render the stars.bmp and then the clouds.bmp over it and when I do the only blending that seems to work is the following.

glBlendFunc( GL_ONE, GL_ONE );

Which I this is like a multiply (something that is done using lightmaps)

I looks ok but the starts are illuminated moreso when the clouds run over them… which is not the effect I’m looking for. I would think I would want the stars to be dimmer when the clouds roll over them dont you?

What is the blendFunc that I should use??

NOTE: my bitmaps do not have an alpha channel to them.

Thanks,
Mongoose

If your image doesn’t contain an alpha channel, then why not add one yourself? Allocate memory for another image, but this time with four colorcomponents. Copy each pixel to the new image, and on your own, add an alpha component based on the color of the image. Or to save memory (unless you are using clouds with different colors at different places), create an image with the alpha channel ONLY, and set color on the polygon you draw the texture on, to set cloud color.

And of course, depending on the result you want, and how you do it with the alpha channel, you might want to try different kind of blend functions.

If using a alpha-only image, I think you should use this blend function: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Then you should draw stars first, then clouds (and remember, in this case, clouds should have greate alpha the thicker the clouds are).

Ok this sounds great. I would love to be able to make an alpha only image, but how?

Can Adobe Photoshop do this for me??

Thankx,
Mongoose

Photoshop does have alpha channel editing support and I’m fairly sure you can save it out seperately. However I dont think you need an alpha channel to get the effect you want. Check out my demo http://www.geocities.com/kyberteknik and see if it works correctly. It has a skybox that has two layers of scrolling transparent clouds with stars behind them. I use GL_DST_ALPHA and GL_SRC_ALPHA respectively for the blending components, the images dont have an alpha channel at all and it works great for me…

Hope that helps.

-BwB

OK I have one more question. Maybe this will help.

All my images are .bmp files. I want to load the bitmap file (GL_RGB) and convert it to an GL_ALPHA type for the rendering pipline. I thought I could do this by the following function.

gluBuild2DMipmaps( GL_TEXTURE_2D, GL_ALPHA, pTex->sizeX, pTex->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pTex->data );

I want to do this so I can do the following blend function on it.

glBlendFunc( GL_SRC_ALPHA, GL_SRC_ALPHA_MINUS_ONE );

Does this make sense… However it does not seem to work for me!?

Any clue??

Thankx,
Mongoose

Your combination of parameters in gluBuild2DMipmaps doesn’t make sense at all. OpenGL doesn’t know how to convert your RGB image into a single alpha channel (there are quite a few algorithms to do this to achieve different results). You can, however, draw a greyscale bitmap over your clouds, and upload it as an alpha image. Or create your own alpha image, like this.


unsigned char alphaImage = (unsigned char)calloc(sizeW*sizeH, sizeof(unsigned char));
for(int i=0; i<sizeW; i++)
{
for(int j=0; i<sizeH; j++)
{
alphaImage[i*sizeH + j] = (rgbImage[[i*sizeH + j + 0]+rgbImage[[i*sizeH + j + 1]+rgbImage[[i*sizeH + j + 2]) / 3;
}
}
gluBuild2DMipmap(GL_TEXTURE_2D, GL_ALPHA, sizeW, sizeH, GL_ALPHA, GL_UNSIGNED_BYTE, alphaImage);

Now you have an alpha image, based in the total light intensity in the image.

[This message has been edited by Bob (edited 09-26-2000).]


unsigned char alphaImage = (unsigned char)calloc(sizeW*sizeH, sizeof(unsigned char));
for(int i=0; i<sizeW; i++)
{
for(int j=0; i<sizeH; j++)
{
alphaImage[i*sizeH + j] = (rgbImage[[i*sizeH + j + 0]+rgbImage[[i*sizeH + j + 1]+rgbImage[[i*sizeH + j + 2]) / 3;
}
}
gluBuild2DMipmap(GL_TEXTURE_2D, GL_ALPHA, sizeW, sizeH, GL_ALPHA, GL_UNSIGNED_BYTE, alphaImage);

Are you sure your inner loop is right??

your second for statement doesn’t make sense to me.

No, it’s suppose to be j all the way in the second for-loop