Hello all.
I am trying to blend two textures. One is a full RGB texture, with all 1.0’s for the Alpha, and the second texture is no RGB (set to 0.0’s), and an alpha pattern. I want to blend them so the final image is the RGB of the first texture, and the aplpha of the second texture.
tex1=(r,g,b,1) tex2=(0,0,0,a) final=(r,g,b,a)
I’m using the multitexture hardware extensions.
Here’s how I load the textures:
glBindTexture(GL_TEXTURE_2D, *tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA8,cinfo.output_width,cinfo.output_height,GL_RGB,GL_UNSIGNED_BYTE,ourImageArray);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *tex);
//and load the alpha image
glBindTexture(GL_TEXTURE_2D, *g); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,TextureImage[0]->sizeX,TextureImage[0]->sizeY,GL_RGBA,GL_UNSIGNED_BYTE,beta); glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *g);
Here’s the what I do to draw them:
glEnable(GL_BLEND);
glAlphaFunc(GL_GREATER, 0.01f);
glEnable(GL_ALPHA_TEST);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,*tex);
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *g);
…
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,…);
glMultiTexCoord2fARB(GL_TEXTURE2_ARB,…);
glVertex3f(…);
The code above draws the texture with full transparencey where alpha < 0.01f. But I need to blend the alpha of the second texture with the first texture, so I get a smooth blend. Right now there is no blending.
I’ve been reading about blending, and I believe that I need a glBendFunc(…) call in there. I do not know where to put it, or what parameters to call.
Any ideas would be appreciated.
Thanks.