3
\$\begingroup\$

In libgdx/OpenGL ES I want to render multiple semitransparent textures while keeping the alpha still semi transparent. For example If I render a 0.5 alpha circle on top of another 0.5 alpha circle, alpha should remain 0.5, output alpha should be maximum value of input alpha and destination alpha.

I looked a bit, it looks like glBlendEquationSeparate(GL_FUNC_ADD, GL_MAX) should do the trick, but it is not GL_MAX operator is not available for OpenGL ES. Weirdly, it works when I use integer value for (0x8008) but I guess I can't trust that :D

How can I achieve such an effect?

\$\endgroup\$
1
\$\begingroup\$

I believe GL_ONE_MINUS_SRC_ALPHA is what you are looking for.

If you are using a SpriteBatch you can enable blending like this:

batch.enableBlending();
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

Otherwise you can call the OpenGL functions directly:

Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
\$\endgroup\$
  • \$\begingroup\$ Nah, with those settings blended areas are not correctly drawn. While drawing a lower alpha pixel on higher alpha, it reduces the alpha \$\endgroup\$ – taytay Mar 11 '14 at 11:06
1
\$\begingroup\$

Depending on the device(s) you are targeting, you may be able to use GL_MAX. It is defined in the gl2ext.h header file. You should check that the device supports the extension called GL_EXT_blend_minmax (it sounds like the device you are using does support it).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.