0
votes

I've got 2 RGBA8 textures:

A) The "main" texture with data for display in all channels

B) The "gradient" texture that only has meaningful data in alpha (of course this should really just be an A8 texture)

Using OpenGLES 1.1 texture combiners, I'd like the resulting texel to copy RGB from texture #A, and use an alpha modulated from both textures (alpha from texture A * alpha from texture B).

I'm having trouble with my texture combiner code (I already tried monkeying with it) and was wondering if anyone can spot the problem:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, geometryP->texName);
glTexCoordPointer(2, GL_BYTE, 0, geometryP->texCoordsP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, mGradientTextureName);
glTexCoordPointer(2, GL_BYTE, 0, geometryP->texCoordsP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);

The result I get basically just looks like RGBA from texture #A (the main texture).

3

3 Answers

2
votes

I may be off, but are you sure it's note a texture coordinate problem ? you don't seem to be doing a glClientActiveTexture before calling the glTexCoordPointer...

1
votes

BindTexture, TexEnv, glEnable(GL_TEXTURE_2D) and Texture Matrix are affected by ActiveTexture, but TexCoordPointer is not. In fact, the second TexCoordPointer was unnecessary, and the first call could have been done in any order. I've been monkeying some more and my most recent code is:

glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, geometryP->texName);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mGradientTextureName);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);  
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);

I have a feeling this new code is correct, but my gradient texture may be wrong, so I'm still working on it :)

0
votes

Bahbar, sorry you were exactly right about the glClientActiveTexture -- I hadn't heard of that one before (and was confusing it with glActiveTexture in my last response). But after using that one and setting the glEnableClientState and glTexCoordPointer for TEXTURE1, it works!