I have a drawn a filled circle using ShapeRenderer and now I want to draw this circle as a transparent one. I am using the following code to do that: But the circle is not coming as transparent. Also, I checked th libgdx API and from the wiki, it says that, need to Create CameraStrategy. Has somebody faced similar issue ever before? If so, please give me some clues. Thanks in advance.
Gdx.gl.glEnable(GL10.GL_BLEND);
Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
drawFilledCircle();
Gdx.gl.glDisable(GL10.GL_BLEND);
private void drawFilledCircle(){
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeType.FilledCircle);
shapeRenderer.setColor(new Color(0, 1, 0, 1));
shapeRenderer.filledCircle(470, 45, 10);
shapeRenderer.end();
}
The following code is working for me in this case, maybe it will help someone else:
Gdx.gl.glEnable(GL10.GL_BLEND);
Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeType.FilledCircle);
shapeRenderer.setColor(new Color(0, 1, 0, 0.5f));
shapeRenderer.filledCircle(470, 45, 10);
shapeRenderer.end();
Gdx.gl.glDisable(GL10.GL_BLEND);
First we need to enable blending:
Gdx.gl.glEnable(GL10.GL_BLEND);
And make sure that you don't call SpriteBatch.begin()
and SpriteBatch.end()
between that line of code and your Shaperender.drawSomething()
line of code. I don't know why but that's what works in my case
Only this worked for me :
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
//Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); // <<< this line here makes the magic we're after
game.shapeRenderer.setProjectionMatrix(camera.combined);
game.shapeRenderer.begin(ShapeType.Filled);
go.drawShapes();
game.shapeRenderer.end();
//Gdx.gl.glDisable(GL20.GL_BLEND);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With