Skip to content

Instantly share code, notes, and snippets.

@Densamisten
Created September 11, 2024 14:22
Show Gist options
  • Select an option

  • Save Densamisten/28d0a1d7d12991d3d89a5f7a65ae73c0 to your computer and use it in GitHub Desktop.

Select an option

Save Densamisten/28d0a1d7d12991d3d89a5f7a65ae73c0 to your computer and use it in GitHub Desktop.
package exonihility.client.gui.hud;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import org.joml.Matrix4f;
public class Circle implements HudRenderCallback {
@Override
public void onHudRender(DrawContext drawContext, RenderTickCounter tickDelta) {
// Example: Draw a red circle at (100, 100) with radius 50
drawCircle(drawContext, 100, 100, 50, 1.0f, 0.0f, 0.0f, 1.0f);
}
public void drawCircle(DrawContext context, int x, int y, int radius, float r, float g, float b, float a) {
RenderSystem.setShaderColor(r, g, b, a);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Matrix4f matrix = context.getMatrices().peek().getPositionMatrix();
BufferBuilder bufferBuilder = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(x, y, 0).color(r, g, b, a);
int segments = 100;
for (int i = 0; i <= segments; i++) {
float angle = 2 * (float) Math.PI * ((float) i / segments);
float cx = (float) Math.cos(-angle) * radius;
float cy = (float) Math.sin(-angle) * radius;
bufferBuilder.vertex(matrix, x + cx, y + cy, 0).color(r, g, b, a);
}
BuiltBuffer builtBuffer = bufferBuilder.end();
BufferRenderer.drawWithGlobalProgram(builtBuffer);
RenderSystem.disableBlend();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment