aka wqzxqz
-
Автор темы
- #1
код;
Java:
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;
import java.awt.*;
public class GradientAndOutlineUtil {
public static void drawRoundedGradientOutline(float x, float y, float width, float height, float radius, float lineWidth, Color startColor, Color endColor) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.shadeModel(GL11.GL_SMOOTH);
GlStateManager.lineWidth(lineWidth);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);
float segments = 32.0f;
float angleIncrement = (float) (Math.PI / (segments / 2.0));
for (int i = 0; i <= segments; i++) {
float angle = angleIncrement * i;
float colorFactor = i / segments;
Color currentColor = blendColors(startColor, endColor, colorFactor);
float r = currentColor.getRed() / 255.0f;
float g = currentColor.getGreen() / 255.0f;
float b = currentColor.getBlue() / 255.0f;
float a = currentColor.getAlpha() / 255.0f;
buffer.pos(x + radius - Math.cos(angle) * radius, y + radius - Math.sin(angle) * radius, 0).color(r, g, b, a).endVertex();
buffer.pos(x + width - radius + Math.cos(angle) * radius, y + radius - Math.sin(angle) * radius, 0).color(r, g, b, a).endVertex();
buffer.pos(x + width - radius + Math.cos(angle) * radius, y + height - radius + Math.sin(angle) * radius, 0).color(r, g, b, a).endVertex();
buffer.pos(x + radius - Math.cos(angle) * radius, y + height - radius + Math.sin(angle) * radius, 0).color(r, g, b, a).endVertex();
}
tessellator.draw();
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
private static Color blendColors(Color start, Color end, float factor) {
int r = (int) (start.getRed() + (end.getRed() - start.getRed()) * factor);
int g = (int) (start.getGreen() + (end.getGreen() - start.getGreen()) * factor);
int b = (int) (start.getBlue() + (end.getBlue() - start.getBlue()) * factor);
int a = (int) (start.getAlpha() + (end.getAlpha() - start.getAlpha()) * factor);
return new Color(r, g, b, a);
}
}