GL_MAX / LibGDX problem

Hi there,

I want to render 2 overlapping, transparent sprites. But even where they overlap, the resulting color should not be different compared to the resulting color of one rendered sprite. I read about blending in OpenGL and i think, glBlendEquation(GL_MAX) is what i need. Here is my LibGdx example:

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class GLMaxTest implements ApplicationListener {

    OrthographicCamera cam;
    SpriteBatch batch;
    Texture tex;

    @Override
    public void create() {
        Pixmap pixmap = new Pixmap(4,4, Pixmap.Format.RGBA8888);

        cam = new OrthographicCamera(2, 2);
        cam.position.set(0, 0, 0);
        cam.update();

        batch = new SpriteBatch(1000);
        batch.setProjectionMatrix(cam.combined);
        batch.enableBlending();

        Pixmap.setBlending(Pixmap.Blending.None);
        pixmap.setColor(new Color(1.0f,0.0f,0.0f,0.3f) );
        pixmap.fill();

        tex = new Texture(pixmap);

        //Gdx.gl.glBlendEquation(GL30.GL_MAX);
        //Gdx.gl.glBlendEquationSeparate(GL30.GL_FUNC_ADD, GL30.GL_MAX);
    }

    @Override
    public void dispose() { }

    @Override
    public void pause() { }

    @Override
    public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        batch.begin();
        batch.draw(tex,0,0);
        batch.draw(tex,-1,-1);
        batch.end();
    }

    @Override
    public void resize(int width, int height) { }

    @Override
    public void resume() { }

    public static void main(String[] args) {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();

        cfg.title = "";
        cfg.useGL30 = true;
        cfg.width = 640;
        cfg.height = 480;
        cfg.resizable = false;

        new LwjglApplication(new GLMaxTest(), cfg);
    }
}

The result:

Woking as intended so far.

When I added “Gdx.gl.glBlendEquation(GL30.GL_MAX);”, this is what I got:

The alpha values seem to get completly ignored.

Then i tried “Gdx.gl.glBlendEquationSeparate(GL30.GL_FUNC_ADD, GL30.GL_MAX);”. But this line does not change anything. This is what was getting displayed again:

What am I missing? Or is this maybe even a LibGDX bug?

Oh, and yeah, first post :slight_smile: