I am trying to make a stencil in a Libgdx project . So far, I have only succeeded in stencil polygons (code after illustration).
QUESTION: . How should I screen non-polygon forms in OpenGL ES 2.0? (i.e. I don’t want transparent pixels to be drawn in the stencil buffer)
How should I achieve this without using GL_ALPHA_TEST (since OpenGL ES 2.0 does not allow it)?
Any help or pointers with thanks and thanks in advance.
EDIT: It would be very helpful if you could provide me some code for understanding.
Please consider the illustration below:

This is the rendering code:
@Override
public void render(float delta) {
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_STENCIL_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT );
stage.act();
stage.draw();
Gdx.gl20.glColorMask(false, false, false, true);
Gdx.gl20.glDepthMask(false);
Gdx.gl20.glClearStencil(0x0);
Gdx.gl20.glEnable(GL20.GL_STENCIL_TEST);
Gdx.gl20.glStencilFunc(GL20.GL_ALWAYS, 0x1, 0x1);
Gdx.gl20.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_REPLACE);
batch.begin();
batch.draw(heart, 0, i+50);
batch.end();
Gdx.gl20.glColorMask(true, true, true, true);
Gdx.gl20.glDepthMask(true);
Gdx.gl20.glStencilFunc(GL20.GL_NOTEQUAL, 0x1, 0x1);
Gdx.gl20.glStencilOp(GL20.GL_KEEP, GL20.GL_KEEP, GL20.GL_KEEP);
batch.begin();
batch.draw(heart, 0, i);
batch.end();
Gdx.gl20.glDisable(GL20.GL_STENCIL_TEST);
}
source
share