Texture transformation and merge problem


I have two textures and I am merging these two based on rgb value of texture2 using shader. I achieved it using multitexturing and shader :
uniform sampler2D myTexture1;
uniform sampler2D myTexture2;

void main (void)
vec4 texval1 = texture2D(myTexture1, vec2(gl_TexCoord[0]));
vec4 texval2 = texture2D(myTexture2, vec2(gl_TexCoord[1]));

if (any(greaterThan(texval2.rgb, vec3(0.0))))
	gl_FragColor = texval2;
	gl_FragColor = texval1;


I am drawing these textures then like :



myShader->sendUniform1i(“myTexture1”, 0);
myShader->sendUniform1i(“myTexture2”, 1);

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

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glVertex3f(0.0, size*1.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glVertex3f(size1.0, size1.0, 0.0);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glVertex3f(size*1.0, 0.0, 0.0);


This works perfectly fine.

Now my problem is that I want to apply some transformation to texture1 BUT not to texture2.

So I tried using texture matrix just before drawing the textures. I tried something like :

// Transform texture 1
::glBindTexture(GL_TEXTURE_2D, texture1);
::glMatrixMode (GL_TEXTURE);

// NO transformation in texture2
::glBindTexture(GL_TEXTURE_2D, texture2);
::glMatrixMode (GL_TEXTURE);

And then I changed vertex shader like :
void main(void)
gl_TexCoord[0] = gl_TextureMatrix[0]*gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

This didn’t give me the results as exected. After this my texture1 became half the size and it got shifted to lower left corner and the remaining screen area filled with some part of texture1 repeated. Texture1 was fine though. Merging was fine also. I guess this happened because I didnt change the texture mapping code. Actually I want the result as I would have got if i had done the transformation in model view matrix.
But problem with that is …it would apply to both texture1 and 2. So in short my problem is :

  1. Apply transformation to texture1 and not to 2.
  2. Merge two textures using color value in texture2 using shader.

Is point 1 possible to achieve with still using multi texturing ?

One other apparent solution is to get rid of multitexturing and use the shader ONLY to change the alpha value of texture2 pixels based on color and then perform alpha blending. But I dont know how to make shader only affect texture2 and not texture1 ?

Before switching to texture matrix mode, select texture unit using glActiveTexture(GL_TEXTUREn) call.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.