Drawing transparent ShapeRenderer in libgdx

UVM picture UVM · Feb 5, 2013 · Viewed 28.4k times · Source

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();

}

Answer

UVM picture UVM · Feb 6, 2013

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);