multitexturing

hello, just discovered how to use arb_multitexture, and wanted to know some stuff:

  1. How can I configure two texture units to “add” two textures

  2. How can I configure two texture units to “multiply” two textures (1st one is a real texture and the 2nd is a lightmap, for example)

  3. how does per-vertex coloring of one of the stages affect the process?

  4. how does per-vertex alpha blending affect the process?

code snippets will be very appreciated. Thanks,

  1. Use the GL_ADD operation with the GL_texture_env_combine extension (GL_COMBINE_EXT texture environment mode) on stage1 with Arg0 set to GL_PREVIOUS_EXT and Arg1 set to GL_TEXTURE. Just set stage0 to GL_REPLACE mode.

  2. Same as above except use GL_MODULATE operation.

  3. depends upon texture environment mode, material settings and/or lighting.

  4. same as 3

I guess you mean something like:

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_ADD);
glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_TEXTURE);
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_PREVIOUS_EXT);

Could you tell me which parameters go where in your answer to my #1 question?

Originally posted by DFrey:
[b]1) Use the GL_ADD operation with the GL_texture_env_combine extension (GL_COMBINE_EXT texture environment mode) on stage1 with Arg0 set to GL_PREVIOUS_EXT and Arg1 set to GL_TEXTURE. Just set stage0 to GL_REPLACE mode.

  1. Same as above except use GL_MODULATE operation.
  1. depends upon texture environment mode, material settings and/or lighting.
  1. same as 3[/b]

To add two textures A and B:

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,A);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D,B);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_ADD);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_EXT,GL_ADD);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_EXT,GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_EXT,GL_SRC_ALPHA);

In this example I’m also adding the alpha channels. You don’t have to if you don’t want to. Also I set stage0 to GL_REPLACE, it could just as well be GL_DECAL or GL_MODULATE.

[This message has been edited by DFrey (edited 01-19-2001).]

Or, you could just use the texenv add extension and use GL_ADD as your texture environment mode.

  • Matt

I don’t know why GL_COMBINE_EXT stuck in my head, to multiply you could just use GL_MODULATE as the mode for stage1. Whole lot easier that way.

Ok, thanks, but it still doesn’t work. I have two versions of the code, which I guess are equivalent, and both yield the same wrong result

version #1:

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,IDTEX1);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,IDTEX2);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

version #2:

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,IDTEX1);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,IDTEX2);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SRC_COLOR);

In both cases the first texture is displayed, as if there was no multitex. Am I missing something? do i need to initialize anything for this to work? I’m using a TNT2 Ultra, which should have no problem painting this… i’m quite desperate…

Looks like it should work off the top of my head. Can you try binding the textures to the opposite texture units? In other words, swap the lines:
glBindTexture(GL_TEXTURE_2D,IDTEX1);
and
glBindTexture(GL_TEXTURE_2D,IDTEX2);
but leave everything else the same. What do you get then? Does it simply show the correct lightmap (or whatever your second texture is)? If so, that may indicate you are doing something wrong with your texture coordinates on the second texture unit.

Also try drawing only tex1 and make sure it looks fine, then try drawing only tex2 and be sure it looks fine. Otherwise, it could be possible that one of your textures could be loading incorrectly.

ok, fixed it, thanks!!!

What i did was to assume the multitex code was right, and then check the other stuff. In our case, we use a texture caching engine (we have quite a bit of code ;-)), and texture indices just weren’t well defined for the multitexture code. Once that has been solved, it works perfectly

Originally posted by LordKronos:
[b]Looks like it should work off the top of my head. Can you try binding the textures to the opposite texture units? In other words, swap the lines:
glBindTexture(GL_TEXTURE_2D,IDTEX1);
and
glBindTexture(GL_TEXTURE_2D,IDTEX2);
but leave everything else the same. What do you get then? Does it simply show the correct lightmap (or whatever your second texture is)? If so, that may indicate you are doing something wrong with your texture coordinates on the second texture unit.

Also try drawing only tex1 and make sure it looks fine, then try drawing only tex2 and be sure it looks fine. Otherwise, it could be possible that one of your textures could be loading incorrectly.[/b]