help with TexEnv

Started by
1 comment, last by soconne 19 years, 2 months ago
I'm trying to render an object with its texture, but I only want the alpha component of the texture to be applied and i want the rgb components to be just black. I tried calling glTexEnv like so glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_ZERO); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_ZERO); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_TEXTURE0); glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA); But when I render, the texture still shows through. Anybody know how to do this correctly ?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
As a black color source, you can use either the primary color or the texture evironment color. The RGB part is just a GL_REPLACE of this color source, and the A part is a GL_REPLACE of the texture alpha channel. This example uses the texture environment color.
GLfloat black[] = {0, 0, 0, 1};glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, black);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT_COLOR);glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
Thanks a lot, it worked perfectly.
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement