Loading...
Logo
Processing Forum
Hi everyone,

I'm new to Processing and eventually developed with Java but new to OpenGL so sorry if this is a very elemental question.
For my testing project, I'm using the codeanticode GLGraphics library and the core OpenGL.

I have a question in how to set the alpha channel of a texture to blend with another. Both textures will be drawn with image().
Copy code
  1. GLTexturePingPong textureOne;
  2. GLTexture textureTwo;

textureOne has white background and a red circle on the middle and is semi-transparent (not 100% red).
textureTwo comes from an image.

Copy code
  1. image(textureTwo, 0, 0);
  2. image(textureOne, 0, 0);

As you see I want to place one texture on top of the other but setting the alpha channel of the textureOne in the way that the white texture pixels are considered as "transparent" and the other that are not colored at all "sem-transparent".

Is that possible? Do I have to enable some GLGraphics constants to enable blending? Is there any method like
Copy code
  1. textureOne.setAlphaChannel(255);
to consider white as the alpha channel?

Thank you very much,
Adrian.

Replies(1)

Solved!
After some research and messing around I found a soultion I post here.
Correct me if any mistake please.

The key is to work with
Copy code
  1. processing.opengl.*,
  2. javax.media.opengl.GL;
  3. codeanticode.glgraphics.GLGraphicsOffScreen;
and of course the textures are stored as GLTexture and GLTexturePingPong.

Then when drawing could do a substractive image blending.
Copy code
  1. gl.glEnable(GL.GL_BLEND);
  2. gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO);

  3. image(textureTwo, 0, 0);
  4. image(textureOne, 0, 0);

  5. gl.glDisable(GL.GL_BLEND);

For more info, if want to do an additive image blending only have to set
Copy code
  1. gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);

Thanks,
Adrian.