Alpha textures

Started by tomster, May 27, 2009, 13:59:44

Previous topic - Next topic

tomster

Hi,

Is it possible to create a texture that has an alpha channel only?
I want a texture that will only affect the transparency of a fragment but use the original color (blended of course).




bobjob


broumbroum

This is texture environment alpha blending. With OpenGL, you can configure each texture rgba rendering to COMBINE alpha and color channels with the texture environment parameters. I use this as I "blend" the texture to create a black mask for the SHADOWS or to make a GLOWING EFFECT :
/** SET COLOR BLEND HERE*/
GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, FloatBuffer.wrap(new float[]{colorBlend[0], colorBlend[1], colorBlend[2], colorBlend[3]}));
/** MODE IS COMBINE*/
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL13.GL_COMBINE);
/** :::: part 1 :::: COLOR COMBINES WITH MODULATION BETWEEN TEX AND ENV_COLOR set above */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_RGB, GL11.GL_MODULATE);
/** MODULATE COLOR */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_RGB, GL11.GL_TEXTURE);
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE1_RGB, GL13.GL_CONSTANT);
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND1_RGB, GL11.GL_SRC_COLOR);

/** :::: part 2 :::: ALPHA COMBINES WITH MODULATION BETWEEN TEX AND ENV_COLOR set above */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_COMBINE_ALPHA, GL11.GL_MODULATE);
/** SOURCE0 must be TEXTURE ALPHA */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE0_ALPHA, GL11.GL_TEXTURE);
/** THEN SOURCE1 will explicitely use the COLOR-ALPHA VALUE */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_SOURCE1_ALPHA, GL13.GL_CONSTANT);
/** THIS IS THE ALPHA-BLENDING THAT WILL USE THE SRC (WHICH IS SOURCE0) as DESTINATION */
            GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL13.GL_OPERAND1_ALPHA, GL11.GL_SRC_ALPHA);


This must be set for EVERY texture bound, if color has alpha channels greater than 0.0f, then the texture will be BLENDED with the specified ENV_COLOR. OPENGL DOC : http://www.opengl.org/sdk/docs/man/xhtml/glTexEnv.xml
This process has been mentioned in this book : http://www.amazon.fr/Open-GL-2-0-Guide-officiel/dp/2744020869