How can I clip a circle using libGDX? Clipping a rectangle very easy Gdx.gl.glScissor(int x,int y,int width,int height)
. Is there any method to clip a circle or do I need some algorithm?
Asked
Active
Viewed 760 times
2
-
That command works for anything you draw. – Tenfour04 Sep 19 '15 at 16:55
-
While searching for "libgdx clip circle" doesn't yield much help, perhaps searching for a general opengl solution might help you find something that you can use. Try googling "opengl clip circle", for example. – tobloef Sep 19 '15 at 16:58
-
That command works for anything you draw??? so give me an example using circle?? the command takes position and **width** and **height** as parameters what about circle **radius**?? – mobarmig Sep 19 '15 at 20:46
-
Are you saying you want to cut a slice of the pie, as it were, for the circle clipping? – Malkierian Sep 20 '15 at 05:56
-
Your question sounded to me like you were asking how to clip a circle, not how to clip an arbitrary shape *with* a circle. The clip command always clips a rectangle out of whatever you draw after it. For anything other than a rectangle, you cannot simply clip. You need to use multi-texturing with a custom shader program. But the way to do it depends on exactly what you are doing. Are you cutting the same circle out of many sprites or just one? – Tenfour04 Sep 20 '15 at 14:27
-
And are you clipping multiple different circles from different areas on the screen. – Tenfour04 Sep 20 '15 at 14:32
-
I am drawing multiple objects using **PolygonSpriteBatch** and **SpriteBatch** and **ShapeRenderer** and I would like to draw objects (lines , images, fill shapes) inside a circle , you said I need **multi-texturing with a custom shader program** can you explain more or give some example or link to docs. – mobarmig Sep 21 '15 at 11:13
-
OK I found some examples and docs for shader program and there is another way to do clipping with depth buffer , I am just search for easiest it solution to do circle clipping?? – mobarmig Sep 21 '15 at 11:47
-
http://stackoverflow.com/questions/37716128/modify-picture-resource-to-rounded-rectangle-border-in-libgdx – Jing Hu Jul 07 '16 at 09:54
1 Answers
1
It is possible to clip circle by using depth buffer :
//clear screen
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
//clear depth buffer with 1.0 :
Gdx.gl.glClear(GL10.GL_DEPTH_BUFFER_BIT);
//set the function to LESS
Gdx.gl.glDepthFunc(GL20.GL_LESS);
//enable depth writing
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
//Enable depth mask and disable RGBA color writing
Gdx.gl.glDepthMask(true);
Gdx.gl.glColorMask(false, false, false, false);
//rendering(Circle ect..) primitive shapes
shapeRenderer.begin();
shapeRenderer.circle(x, y, radius);
shapeRenderer.end();
batch.begin();
//Enable RGBA color writing
Gdx.gl.glColorMask(true, true, true, true);
//Enable testing
Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
//Discards pixels outside masked shapes
Gdx.gl.glDepthFunc(GL10.GL_EQUAL);
batch.draw(...);
batch.end();

mobarmig
- 43
- 4