Multi-texturing and different blending

I want to be able to set several textures on the same triqngles.
But i want also to be able to choose the percentage of blending for each textures in real time.

For example:
A blue sphere + 10% of one texture + 50% of the texture of a text (like in some 3d modelers).

Is it possible to do it with some OpenGL functions?
How an i do that?
I have found several examples of multi-texturing, but the percentage of each textures seems to be always the same thing (50% with 2 textures).

I could change the alpha channel of my textures when i load it, but it would be slow to process and reload my textures when i change the percentages in real time.

Thanks

You want to use the GL_ARB_texture_env_combine extension. It is kind of difficult to understand at first. You should look up the manual page for that extension and study it over and over until you understand it. The combine mode that you want to use is GL_INTERPOLATE_ARB, which you do like this:

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

Then you need to use something as an operand to tell GL how much you want of each texture. You can use the primary color, primary alpha, texture color or a variety of other operands for this.

Ok, i will study it.
Thanks.

I have tried this code, but it does not work very well. I can’t change the alpha channel of the first texture and the color are not very good.
I can change the alpha channel of the second texture (1/alpha) but not its color.

The documentation is not very clear. GL_INTERPOLATE_ARB need 3 sources in the documentation, but what is it?

  
float color[4];
	
// 1st Texture
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texID);

// RGBA color
color[0]=0.5f; // It works (but not very well)
color[1]=0.5f; // It works (but not very well)
color[2]=0.5f; // It works (but not very well)
color[3]=0.7f; // Dosen't work
		
////// 1st texture with color (without alpha ?)//////////////	
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_BLEND);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,color);
//////////////////////////////////////////////////////////	

// 2nd Texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texID2);
	
// RGBA color
color[0]=1.0f; // Dosen't work
color[1]=0.0f; // Dosen't work
color[2]=0.0f; // Dosen't work
color[3]=0.5f; // it works (1/alpha)
		
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_BLEND);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,color);
	
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
	
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB );
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );
	


glBegin(GL_QUADS);	
glColor3f(1.0f,1.0f,1.0f);	
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 
			0.0f,
			1.0f
		);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 
			0.0f,
			1.0f
		);
glVertex3f( -1.0f, 1.0f, 0.0f);	

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 
			1.0f,
			1.0f
		);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 
			1.0f,
			1.0f
		);
glVertex3f( 1.0f, 1.0f, 0.0f);
		
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 
			1.0f,
			0.0f
		);    
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 
			1.0f,
			0.0f
		);    
glVertex3f( 1.0f, -1.0f, 0.0f);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB,  
			0.0f,
			0.0f
		);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,  
			0.0f,
			0.0f
		);
glVertex3f( -1.0f, -1.0f, 0.0f);
		
glEnd();	

The combiner form for lerp is
lerped value = arg0arg2 + arg1(1-arg2).

So, from your example, you want 60% of the first
texture, 40% of the second:

float color[4] = { 1, 1, 1, 0.6 };

glTexEnvi( GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB );

glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA );

There are alternatives to this for compositing images the way you describe. You might consider a multi-pass approach, where you scale each pass’ contribution by the percentage of opacity. For the example above, your first pass would contribute 60% to the final image, the second 40%. This is know in some circles as splatting, and is an excelent technique for texturing terrains.

thanks, il will try it.

I have tried your setting for the second texture.

It takes the colors of the previous texture (T0) and the color of the 2nd texture with 1/alpha for the second texture.

But the problem is that if i use:

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA );

I can use the alpha value of color[] but not the RGB color of color[].
If i use:

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR );

I can use the RGB color of color[] but not the its alpha value.

Is it possible to use the RGB color AND the alpha value of color[], or do i have to use 2 passes?

I have another problem. I use this setting for the first texture:

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_BLEND);
	glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,colorArray);

With that i can change the color of my texture but the alpha value do not work (i have always alpha=1). I have the same problem without multi-texturing.
Why?