interpolate 2 textures - mission impossible?

Hello all,
I just trying to interpolate 2 textures (using ARB_multitexture) and it doesn’t work at all. Please don’t you have any working example of this simple thing?
My code is below. Thanks for any response, I’m
quite desperate already :-?
Jirka

CODE************************:

// loading RGB textures
tex[0] = read_texture(“data/brick.rgb”, &texwid, &texht, &texcomps);
tex[1] = read_texture(“data/brick2.rgb”, &texwid, &texht, &texcomps);

//glGenTextures(2, texNames);
glBindTexture(GL_TEXTURE_2D, texNames[0]); setTexParams();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texwid, texht, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex[0]);
glBindTexture(GL_TEXTURE_2D, texNames[1]); setTexParams();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texwid, texht, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex[1]);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texNames[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texNames[1]);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_ONE_MINUS_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_CONSTANT_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);

glDisable( GL_BLEND );

glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, 0.f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.f, 0.f );
glVertex3f(0., 0., 0.);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.f, 1.f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.f, 1.f);
glVertex3f(0., 1., 0.);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.f, 1.f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.f, 1.f);
glVertex3f(1., 1., 0.);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.f, 0.f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.f, 0.f);
glVertex3f(1., 0., 0.);
glEnd();

What card/driver are you using?

How do you define “not working at all?” What do you see?

And why did you comment out your glGenTextures call?

Oh thanks a lot. The problem was in that commented row. Such a stupid bug…

However the texture have different colour from original image. Hmmm.

I’m using riva TNT2 card/driver nvidia under Linux.

Thanks again.

Originally posted by Korval:
[b]What card/driver are you using?

How do you define “not working at all?” What do you see?

And why did you comment out your glGenTextures call?[/b]

there still remains problem, that both images are affected by alpha value before interpolation. ie. the alpha is not used only as interpolation weight but also as alpha value for both images. How can I forbid ALPHA value change in my previous code above?

Thank you a lot.

J.

I’ve done exactly what you are trying to do. Just bind your first texture as texunit0, and then create an alphamap, which is simply a black and white bitmap consisting of the alpha values for your quad or whatever you’re drawing. bind this alphamap as texunit1, and then bind your second texture as texunit2. then set the texunit2’s alpha source as texunit1. here’s the code for this

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, alphamap);

glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture2);
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_TEXTURE0); 
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR); 

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

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

Hope this helps.

Oh yeah, I almost forgot. When you load the alphamap, you’ll have to create an alphabit for the data when you load it in. Thus instead of having only r,g,b values, you’ll have to add a 4th value, rgba, and put any of the r, g, or b values into it. Then you’ll have to change the rgb values all to 0. Then when you call glTexImage2D, you’ll have to pass in GL_RGBA, instead of GL_RGB.

The reason for this is that if you look at the binding of the 3rd texture, texunit2 uses the GL_SRC_ALPHA component of texuni1 as its GL_SOURCE_ALPHA, you ‘could’ change this to GL_SRC_COLOR instead, but I personally experienced some blending problems with this because opengl tried to blend the black and white color of texuni1 to texunit2 and it looked wierd. So if you only want it to blend the first and second texture, then do what i stated above.

ALTHOUGH…you could just bind the alphamap as texunit0, and bind your first texture as texuni1 and set the GL_TEX_ENV_MODE to GL_REPLACE, so the first texture unit is completely replaced, and then set the texunit3 GL_SOURCE_ALPHA to GL_TEXTURE0. This might work as well, but havn’t tried it.

Nice i works already , thanks a lot. Don’t you know, how to interpolate 4 (or even more) textures on 2 texture units? It can be multi pass-rendering - time is no problem, cos I need image. I wasn’t able to mix more than 2 textures on 2 TU. Have you any idea?

Thank you
Jirka