1
\$\begingroup\$

I encountered a problem, where my small entities would be rendered out of the bounds of my radar.

At the time I solved it like this: ensure, that the object would be within the circle, but, that's not optimal, because I need variable scale for different entitie sizes, which causes further problems to be solved.

So is there a way, that I can do the following:

draw all items within the circle and ensure that nothing is drawn outside

I thought about something, like a circle canvas, which draws all, but displays only that, which is in the bounds.

Minimap example

The points and lines within the circle are of a variable width / height. I'd prefer to draw everything, and cut the other stuff off.

Thanks in advance!

€dit: Gosh forgot an important thing: I draw the items with a shaperenderer, and all things are rect's , and it probably wont be polygons

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I did it! Yay, I'm so proud! :P

Ofc I didn't stopped to google, and I found my answer in a depth buffer.

What I'm currently doing is the following stuff

    Gdx.gl.glClearDepthf(1f);
    Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);

    //1. set the function to LESS
    Gdx.gl.glDepthFunc(GL20.GL_LESS);

    //2. enable depth writing
    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);

    //3. Enable depth writing, disable RGBA color writing
    Gdx.gl.glDepthMask(true);
    Gdx.gl.glColorMask(false, false, false, false);

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(1f, 0f, 0f, 0.5f);
    shapeRenderer.circle(x, y, radius);
    shapeRenderer.end();

That enables my circular clipping area

now I draw some shapes:

shaperenderer.begin();
Gdx.gl.glColorMask(true, true, true, true);

//4. Make sure testing is enabled.
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);

//5. Now depth discards pixels outside our masked shapes
Gdx.gl.glDepthFunc(GL20.GL_EQUAL);
shaperenderer.rect(x,y,width,height);
shaperender.end();

And finally you need to disable the depth func, so it's only for this specific purpose, which is clipped

  Gdx.gl.glDepthFunc(GL20.GL_ALWAYS);

I got my informations out of this github project: github

So props to mattdesl!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .