LWJGL
June 18, 2013, 20:54:55 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: Alpha textures  (Read 3226 times)
tomster
Newbie
*
Posts: 8


« on: May 27, 2009, 06:59:44 »

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).



Logged
bobjob
Prolific Timewaster
****
Posts: 335


LWJGL: WOW SO GOOD


« Reply #1 on: May 27, 2009, 07:49:19 »

do you mean masking?

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20
Logged

LWJGL Benchmark online test:
http://have2chat.net/benchmark/
http://have2chat.net/benchmark/fullpage.html (run full OpenGL webpage)
broumbroum
Prolific Timewaster
****
Posts: 324



WWW
« Reply #2 on: May 27, 2009, 14:46:19 »

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 :
Code:

/** 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
Logged

Sf3JSwing project, code repo (Apache License) -  http://www.sourceforge.net/p/sf3jswing
Sf3jswing Project Forum - http://apps.sourceforge.net/phpbb/sf3jswing/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!