libdgx - Shaperenderer - Opacity

Hi, I am wondering about the Shaperenderer: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html

shapeRenderer.begin(ShapeType.FilledCircle);
			 shapeRenderer.setColor(0, 0, 0.4f, 0.3f);
			 shapeRenderer.filledCircle(100,100,20);
			 shapeRenderer.setColor(1, 1, 0, 0.3f);
			 shapeRenderer.filledCircle(100,100,10);
			 shapeRenderer.end();

Normally I would use the spritebatch for drawing, but this time I just want to draw a circle that contains another circle with a different color. In addition the one on the bottom shouldshow through the other. I just don’t get it who to enable the alpha-“function” / if you google it, it always shows articles about the spritebatcher.
I thought

Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);
		     Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

would manage it, but “glEnable(GL10.GL_BLEND)” throws nullpointer…
I am new to opengl-fun and that’s absolutely confusing me, I just don’t get what I am doing wrong ::slight_smile:
thx for help and patience :slight_smile:

Try:

Gdx.gl.glEnable(GL10.GL_BLEND);

But note you should end any begins before doing more drawing if you change blending.


Gdx.gl.glClearColor(1, 1, 1, 1);
	    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	    Gdx.graphics.getGL10().glEnable(GL10.GL_BLEND);
            Gdx.graphics.getGL10().glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

I don’t think that I am drawing sth at the moment or do I missunderstand it?
best regards

edit: Got it, although shaderrenderer uses gl10 I have to modify gl20 :persecutioncomplex:
Does someone know why?

My only guess would be you enabled gl2 in the config (@launcher)

Also keep in mind shapeRenderer is slow and only for debug stuff - an unfortunate reality, you kinda have to do this stuff yourself if you need it (drawline, drawrect, fillCircle, whatever) - I do it with stretched images

You should use Gdx.gl or Gdx.graphics.getGLCommon() for functions that are shared by both GL10 and GL20. That way your code is independent of GL version. :slight_smile: If useGL20 is true, then Gdx.gl10 will return null.

Of course, it doesn’t matter if you use GL10 or GL20 for static constants (like GL_BLEND), since those will never be null.

As said, ShapeRenderer is not the fastest, but it will probably do fine for most purposes. Another downside is that it relies on hardware anti-aliasing; it varies from device to device, and some don’t support it at all.

Also note that if you need lines or rectangles, you can use a regular SpriteBatch; see here.

If you need better performance (i.e. Android), you should look into using images, or if you fancy something slightly more advanced, read up on shaders. :slight_smile:

thx for explanation :slight_smile:
The shaperenderer is just for prealpha-test-debugging-version. In the future I am not sure if I will use spritebatches or shaders. Spritebatches are very easy to use :smiley:
I already did that tut, but I think I have to read more about shaders if I want to use them ;D
Especially because from es 1.0 to 2.0 are some creepy changes and at the moment I often confuse the functions and wonder about the result ;D
I just started learning opengl and maybe I did to big steps so I might haven’t understood everything I thought I understood ::slight_smile:
best regards