Search code examples
javaandroidlibgdx

Libgdx shaperenderer circle draws as triangle due to scaling


Im trying to create rounded squares in Libgdx I have drawn the squares fine and now doing the rounded corners using a circle for each corner

enter image description here

        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(color);
//draw horizontal square
        shapeRenderer.rect(
                (x - ((BLOCK_SIZE / 2) + 5f) / Config.DPI),
                (y - ((BLOCK_SIZE / 2) + 0) / Config.DPI),
                (width + 10) / Config.DPI,
                height / Config.DPI);
//draw vertical square
        shapeRenderer.rect(
                (x - ((BLOCK_SIZE / 2) + 0) / Config.DPI),
                (y - ((BLOCK_SIZE / 2) + 5f) / Config.DPI),
                (width) / Config.DPI,
                (height + 10f) / Config.DPI);


        shapeRenderer.setColor(Color.RED);
//draw first circle (bottom left)
        shapeRenderer.circle(
                (x - ((BLOCK_SIZE / 2) / Config.DPI)),
                (y - ((BLOCK_SIZE / 2)/ Config.DPI)),
                5/Config.DPI
        );

on Expected result Config.DPI = 2;
on Actual Result Config.DPI = 20;

Really I need DPI to be on atleast 50, but the circle completely dissappears then.

Its the scaling, but is there a way to stop this from happening?


Solution

  • There's another circle method with one additional parameter at the end for number of segments.