Use GL_TEXTURE_ENV_COLOR in the second texture stage

Working with the fixed pipeline, assuming that in the first texture unit a texture is dot(3)ted with the primary color (set using glColor4f), is it possible (and how) in the second texture unit to modulate the result from previous stage with GL_TEXTURE_ENV_COLOR ?

In the detail, I need to realize the follwing operation (without to bind a 1x1 texture containing color1 in the second texture unit):

out = (tex0 dot3 color0) * color1

I tried with:

glActiveTexture(GL_TEXTURE0);
glColor4f(color0.r, color0.g, color0.b, color0.a);
glEnable(texture.target);
glBindTexture(texture.target, texture.glHandle);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGBA);
// the first stage (tex0 dot3 color0) works fine!

glActiveTexture(GL_TEXTURE1);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEX_ENV_COLOR, color1);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);

but it doesn’t work.

Thanks in advance!

You must have a valid texture bound to texture unit 1 and texturing must be enabled, even if you’re not using the result from that texture. It’s an odd API restriction that dates back to the time when OpenGL had no COMBINE texture environment.

Many thanks Georg!

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