How to use Multitexture like this?

Started by
12 comments, last by long_xz 17 years ago
sorry,i don't know how to use glDisableClientState(GL_TEXTURE0_ARB).
How does this statement work?
Advertisement
Thank you,godmodder.
If you have any result,please send me a mail.
I have been puzzled about this problem for a long time.
My mail is long_xz@163.com
Wait, do you want Cv = CfC0 + Cf + C1 like you originally posted or Cv = CfC0 + CfC1 = Cf(C0+C1) like what was assumed in the rest of the thread? If the second equation is what you want I think something like this should work...
//Assuming tex0 and tex1 are already bound to GL_TEXTURE0 and GL_TEXTURE1//Setup texunit 0's environment to output C0+C1glActiveTexture(GL_TEXTURE0);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);//Combine function (Arg0 + Arg1)glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);//Arg0 RGB and alpha come from tex0glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE0);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE0);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);//Arg1 RGB and alpha come from tex1glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE1);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE1);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);//Setup texunit 1's environment to output Cf*previousglActiveTexture(GL_TEXTURE1);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);//Combine function (Arg0 * Arg1)glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);//Arg0 comes from the incoming fragmentglTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);//Arg1 comes from the previous texture environmentglTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
You will need at least OpenGL v1.4 or support for GL_ARB_texture_env_crossbar (with the approriate ARB suffixes) in order to access different texture units than the current one as a source in the combine functions. This is also untested but I think it should work.

If you don't mind requiring support for fragment shaders, this simply becomes
vec4 c0 = texture2D(tex0, uv0);vec4 c1 = texture2D(tex1, uv1);gl_FragColor = gl_Color * (c0 + c1);
sorry for my poor english,
the second equation is exactly what i want.
but i have the same question,how to set the texture coordinate?

This topic is closed to new replies.

Advertisement