Multitexturing && Texture With Alpha Channel problem....
I have two textures, while texture0 has no alpha channel(RGB 565), and texture1 has alpha channel (RGBA8888), i export&load them via pvr format.
so the final rgb = texture0.rgb + (texture1.rgb * texture1.alpha). //and there is no need to blend with background color
I am new to opengl es, and i found glTexEnv(xxx) is so hard to understand and use.....
I've tried code in "OGLES-1.1_WINDOWS_PCEMULATION_2.03.23.1162\TrainingCours e\10_Multitexture", but the result looks strange, here is my code:
// Set up the Second Texture
// Set the texture environment mode for this texture to combine
myglTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
// Set the method we're going to combine the two textures by.
myglTexEnv(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);//GL_MODULATE
// Use the previous combine texture as source 0
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
// Use the current texture as source 1
myglTexEnv(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
//Set what we will operate on, in this case we are going to use
//just the texture colours.
myglTexEnv(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
myglTexEnv(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_DST_ALPHA);
// Indexed Triangle list
glDrawElements(GL_TRIANGLES, Mesh.nNumFaces * 3, GL_UNSIGNED_SHORT, (unsigned short*)Mesh.sFaces.pData);
Please help me...
Re: Multitexturing && Texture With Alpha Channel problem....
GL_DST_ALPHA is not a valid value for GL_OPERAND1_RGB, I suppose you meant GL_SRC_ALPHA.
However, to do what you want, i.e.
final rgb = texture0.rgb + (texture1.rgb * texture1.alpha)
you need to do the multiplication first, i.e. on texture environment TEXTURE0, and the addition on TEXTURE1. To keep it simple you can set the vertex color to black and use GL_DECAL and GL_ADD.
glColor4ub(0, 0, 0, 255);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);