0

So I use the following code to render a rectangle with inverse rounded corners.

        for (int i = 0; i <= step; ++i) {
            final float angle = i * 90/step-90;
            GL11.glVertex2f((float)(x + curved * Math.cos(Math.toRadians(angle))), (float)(y - curved * Math.sin(Math.toRadians(angle))));

        }
        for (int i = 0; i <= step; ++i) {
            final float angle = i * 90/step+180;
            GL11.glVertex2f((float)(x+width + curved * Math.cos(Math.toRadians(angle))), (float)(y - curved * Math.sin(Math.toRadians(angle))));
        }

        for (int i = 0; i <= step; ++i) {
            final float angle = i * 90/step+90;
            GL11.glVertex2f((float)(x+width + curved * Math.cos(Math.toRadians(angle))), (float)(y+height - curved * Math.sin(Math.toRadians(angle))));
        }

        for (int i = 0; i <= step; ++i) {
            final float angle = i * 90/step;
            GL11.glVertex2f((float)(x + curved * Math.cos(Math.toRadians(angle))), (float)(y+height - curved * Math.sin(Math.toRadians(angle))));
        }

Pretty much what this code does is it renders all of the corners and they all link together to make the shape.

When using GL_LINE_LOOP its correct and looks like this enter image description here

But when I try to make a filled version using the same code I get a weird error (using GL_POLYGON) (for glBegin) The top left corner renders some extra stuff even though nothing would render in that orderenter image description here This is a bit more visible if I change the rounded amount. It looks like thisenter image description here And now a line is noticable even though the order of rendering the points should be going the other way. If anyone knows what I'm doing wrong help would be very nice.

Someone said this is a duplicate, BUT HOW would I change this to all triangles. The corners have a lot of vertecies and GL11.glClear( GL11.GL_STENCIL_BUFFER_BIT ); gives me errors

Could you please provide code that fixes this or a reasonable answer.

  • 1
    GL_POLYGON renders convex polygons only. The polygon you're rendering is concave so you're getting unexpected artefacts. The best way to render what you want is to use the same set of points with an extra initial point in centre, then us GL_TRIANGLE_FAN – PeteBlackerThe3rd Apr 04 '22 at 08:15

0 Answers0