#Circle drawing
65 messages · Page 1 of 1 (latest)
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
This may be of interest: https://canary.discord.com/channels/507304429255393322/1267494078149558322
You need to set uv, light and the normal on the vertex if you want to use that shader - you should see what I mean if you look at method suggestions after color(rgba).
I've already taken another person's code example, thanks.
No problem, hope you succeed
@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);
Not too familiar with gui rendering myself, but I think your light is too low
Hang on a second
Try adding ˋ.setLight(15728880)ˋ after color(rgba)
Without the ˋ
Or it might be called just light(
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.
not working
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();
}
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
Okay, what should I insert into RenderSystem.setShaderLights()? I'm new to java.
I‘m shooting in the dark here, but try new Vector3f(1), new Vector3f(1)
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
Also set a to 1f. If it‘s partially transparent the blending might be doing something wierd
😦
not working
And this?
yes
Does it work?
I set RenderSystem.setShaderLights(new Vector3f(1f), new Vector3f(1f));, but still the problem remains
Strange. Can I see what happens if you don‘t do renderQuarterCircle at all?
okey one sec
Also it‘s definitely worth it to use hotswapping when working with shaders or guis; it‘ll make everything a lot faster
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
Just comment those 4 out
How's that?
Hang on
Yes, I've already done it, now the mine is starting.
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?
0.08235294, 0.08235294, 0.08235294 1.0
RGBA
0xFF151515
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
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
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());
}
Yeah that should do the trick