#Circle drawing

65 messages · Page 1 of 1 (latest)

gilded grotto
#

I want to make a function for drawing circles, but it throws an error.

#

    private static void renderQuarterCircle(MatrixStack matrices, float cx, float cy, float radius, int startAngle, int endAngle, int color) {
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);

        Matrix4f matrix = matrices.peek().getPositionMatrix();

        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;

        VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
        VertexConsumer vertexConsumer = immediate.getBuffer(RenderLayer.getSolid());

        vertexConsumer.vertex(matrix, cx, cy, 0.0f).color(r, g, b, a);

        int segments = 30;
        int totalDegrees = endAngle - startAngle;

        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (totalDegrees * (i / (float) segments));
            float rad = (float) Math.toRadians(angle);
            float x = cx + radius * MathHelper.cos(rad);
            float y = cy + radius * MathHelper.sin(rad);
            vertexConsumer.vertex(matrix, x, y, 0.0f).color(r, g, b, a);
        }

        immediate.draw();
        RenderSystem.disableBlend();
    }
#

java.lang.IllegalStateException: Missing elements in vertex: UV0, UV2, Normal

#

Minecraft crash

dusk pelican
gilded grotto
dusk pelican
#

No problem, hope you succeed

gilded grotto
#

@dusk pelican help pls

#

    private static void renderQuarterCircle(DrawContext context, float x, float y, float radius, int startAngleDeg, int endAngleDeg, int color) {
        // Разбираем цвет
        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;
        FPSBoost.LOGGER.info("RGBA: {}, {}, {}, {}", r, g, b, a);
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);
        RenderSystem.setShaderColor(r, g, b, a);

        BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
        bufferBuilder.vertex(x, y, 0).color(r, g, b, a);

        float startAngle = (float) Math.toRadians(360 - endAngleDeg);
        float endAngle = (float) Math.toRadians(360 - startAngleDeg);
        float angleRange = endAngle - startAngle;
        int segments = Math.max(8, Math.abs(endAngleDeg - startAngleDeg) / 5);
        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (angleRange * (i / (float) segments));
            float cx = (float) Math.cos(-angle) * radius;
            float cy = (float) Math.sin(-angle) * radius;

            bufferBuilder.vertex(context.getMatrices().peek().getPositionMatrix(), x + cx, y + cy, 0).color(r, g, b, a);
        }

        BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
    }
#

    public static void renderRoundedRect(DrawContext context, int x, int y, int width, int height, int radius, int color) {
        context.getMatrices().push();

        context.fill(x + radius, y, x + width - radius, y + height, color);
        context.fill(x, y + radius, x + width, y + height - radius, color);

        // Рисуем 4 скругленных угла
        renderQuarterCircle(context, x + radius, y + radius, radius, 180, 270, color); // Левый верх
        renderQuarterCircle(context, x + width - radius, y + radius, radius, 270, 360, color); // Правый верх
        renderQuarterCircle(context, x + radius, y + height - radius, radius, 90, 180, color); // Левый низ
        renderQuarterCircle(context, x + width - radius, y + height - radius, radius, 0, 90, color); // Правый низ

        context.getMatrices().pop();
    }
#

renderRoundedRect(context, guiX, guiY, panelWidth, panelHeight, roundingUp, 0xFF151515);

gilded grotto
#

why

dusk pelican
#

Not too familiar with gui rendering myself, but I think your light is too low

#

Hang on a second

dusk pelican
#

Without the ˋ

#

Or it might be called just light(

gilded grotto
#

one sec

#

Hmmm....

#

I didn't change the code in any way, but I took a different color and everything is fine with it.

#

Apparently it's really about the light

#

I'll try the updated code now.

gilded grotto
#

    private static void renderQuarterCircle(DrawContext context, float x, float y, float radius, int startAngleDeg, int endAngleDeg, int color) {
        // Разбираем цвет
        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;
        FPSBoost.LOGGER.info("RGBA: {}, {}, {}, {}", r, g, b, a);
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);
        RenderSystem.setShaderColor(r, g, b, a);

        BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
        bufferBuilder.vertex(x, y, 0).color(r, g, b, a).light(15728880);

        float startAngle = (float) Math.toRadians(360 - endAngleDeg);
        float endAngle = (float) Math.toRadians(360 - startAngleDeg);
        float angleRange = endAngle - startAngle;
        int segments = Math.max(8, Math.abs(endAngleDeg - startAngleDeg) / 5);
        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (angleRange * (i / (float) segments));
            float cx = (float) Math.cos(-angle) * radius;
            float cy = (float) Math.sin(-angle) * radius;

            bufferBuilder.vertex(context.getMatrices().peek().getPositionMatrix(), x + cx, y + cy, 0).color(r, g, b, a).light(15728880);
        }

        BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
    }
dusk pelican
# gilded grotto not working

Ehh.. are you sure your color is what you think it is? The most I can suggest without being at a computer is to putting RenderSystem.setShaderLights after the first setColor call and putting both vectors in as a 1

gilded grotto
dusk pelican
#

I‘m shooting in the dark here, but try new Vector3f(1), new Vector3f(1)

gilded grotto
#

    private static void renderQuarterCircle(DrawContext context, float x, float y, float radius, int startAngleDeg, int endAngleDeg, int color) {
        // Разбираем цвет
        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);
        RenderSystem.setShaderColor(r, g, b, a);
        RenderSystem.setShaderLights(new Vector3f(1), new Vector3f(1));

        BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
        bufferBuilder.vertex(x, y, 0).color(r, g, b, a).light(15728880);

        float startAngle = (float) Math.toRadians(360 - endAngleDeg);
        float endAngle = (float) Math.toRadians(360 - startAngleDeg);
        float angleRange = endAngle - startAngle;
        int segments = Math.max(8, Math.abs(endAngleDeg - startAngleDeg) / 5);
        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (angleRange * (i / (float) segments));
            float cx = (float) Math.cos(-angle) * radius;
            float cy = (float) Math.sin(-angle) * radius;

            bufferBuilder.vertex(context.getMatrices().peek().getPositionMatrix(), x + cx, y + cy, 0).color(r, g, b, a).light(15728880);
        }

        BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
    }
#

okey one sec

dusk pelican
gilded grotto
dusk pelican
gilded grotto
dusk pelican
#

Strange. Can I see what happens if you don‘t do renderQuarterCircle at all?

dusk pelican
#

Also it‘s definitely worth it to use hotswapping when working with shaders or guis; it‘ll make everything a lot faster

gilded grotto
#

    public static void renderRoundedRect(DrawContext context, int x, int y, int width, int height, int radius, int color) {
        context.getMatrices().push();

        context.fill(x + radius, y, x + width - radius, y + height, color);
        context.fill(x, y + radius, x + width, y + height - radius, color);

        // Рисуем 4 скругленных угла
        renderQuarterCircle(context, x + radius, y + radius, radius, 180, 270, color); // Левый верх
        renderQuarterCircle(context, x + width - radius, y + radius, radius, 270, 360, color); // Правый верх
        renderQuarterCircle(context, x + radius, y + height - radius, radius, 90, 180, color); // Левый низ
        renderQuarterCircle(context, x + width - radius, y + height - radius, radius, 0, 90, color); // Правый низ

        context.getMatrices().pop();
    }

renderQuarterCircle using where

dusk pelican
#

Just comment those 4 out

dusk pelican
#

Hang on

gilded grotto
dusk pelican
dusk pelican
#

Ok so no background. Here‘s hoping this will be a bit simpler

#

Can you log a r g and b . Hopefully with a separator of some sort so I can see which is which?

gilded grotto
#

RGBA

#

0xFF151515

dusk pelican
#

Yep, give me a sec

#

Ok the colors are correct. Ugh, damn

#

Ok I think I might have it

#

@gilded grotto remove all the methods starting with RenderSystem

gilded grotto
#

    private static void renderQuarterCircle(DrawContext context, float x, float y, float radius, int startAngleDeg, int endAngleDeg, int color) {
        // Разбираем цвет
        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;
        RenderSystem.enableBlend();
        RenderSystem.defaultBlendFunc();
        RenderSystem.setShader(GameRenderer::getPositionColorProgram);
        RenderSystem.setShaderColor(r, g, b, a);
        RenderSystem.setShaderLights(new Vector3f(1f), new Vector3f(1f));

        BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
        bufferBuilder.vertex(x, y, 0).color(r, g, b, a).light(15728880);

        float startAngle = (float) Math.toRadians(360 - endAngleDeg);
        float endAngle = (float) Math.toRadians(360 - startAngleDeg);
        float angleRange = endAngle - startAngle;
        int segments = Math.max(8, Math.abs(endAngleDeg - startAngleDeg) / 5);
        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (angleRange * (i / (float) segments));
            float cx = (float) Math.cos(-angle) * radius;
            float cy = (float) Math.sin(-angle) * radius;

            bufferBuilder.vertex(context.getMatrices().peek().getPositionMatrix(), x + cx, y + cy, 0).color(r, g, b, a).light(15728880);
        }

        BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.disableBlend();
    }
``` I'll save this option just in case
gilded grotto
# dusk pelican <@654932938411999232> remove all the methods starting with RenderSystem

okey


    private static void renderQuarterCircle(DrawContext context, float x, float y, float radius, int startAngleDeg, int endAngleDeg, int color) {
        // Разбираем цвет
        int alpha = (color >> 24) & 0xFF;
        if (alpha == 0) alpha = 255;
        float a = alpha / 255f;
        float r = (color >> 16 & 255) / 255f;
        float g = (color >> 8 & 255) / 255f;
        float b = (color & 255) / 255f;

        BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
        bufferBuilder.vertex(x, y, 0).color(r, g, b, a).light(15728880);

        float startAngle = (float) Math.toRadians(360 - endAngleDeg);
        float endAngle = (float) Math.toRadians(360 - startAngleDeg);
        float angleRange = endAngle - startAngle;
        int segments = Math.max(8, Math.abs(endAngleDeg - startAngleDeg) / 5);
        for (int i = 0; i <= segments; i++) {
            float angle = startAngle + (angleRange * (i / (float) segments));
            float cx = (float) Math.cos(-angle) * radius;
            float cy = (float) Math.sin(-angle) * radius;

            bufferBuilder.vertex(context.getMatrices().peek().getPositionMatrix(), x + cx, y + cy, 0).color(r, g, b, a).light(15728880);
        }

        BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
    }
dusk pelican
#

Yeah that should do the trick

gilded grotto
#

OHH

#

YEEE

#

tnx bro