1 package com.irtimaled.bbor.client.renderers;
3 import com.irtimaled.bbor.client.Camera;
4 import net.minecraft.client.render.BufferBuilder;
5 import net.minecraft.client.render.Tessellator;
6 import net.minecraft.client.render.VertexFormat;
7 import net.minecraft.client.render.VertexFormats;
8 import net.minecraft.client.util.math.MatrixStack;
13 public class Renderer {
14 private final VertexFormat.DrawMode glMode;
16 static Renderer startLines() {
17 return new Renderer(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR);
20 static Renderer startLineLoop() {
21 return new Renderer(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
24 public static Renderer startQuads() {
25 return new Renderer(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
28 public static Renderer startTextured() {
29 return new Renderer(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
32 private static final Tessellator tessellator = Tessellator.getInstance();
33 private static final BufferBuilder bufferBuilder = tessellator.getBuffer();
39 private MatrixStack matrixStack;
41 private Renderer(VertexFormat.DrawMode glMode, VertexFormat vertexFormat) {
42 bufferBuilder.begin(glMode, vertexFormat);
46 public Renderer setMatrixStack(MatrixStack stack) {
47 this.matrixStack = stack;
52 public Renderer setColor(Color color) {
53 return setColor(color.getRed(), color.getGreen(), color.getBlue())
54 .setAlpha(color.getAlpha());
57 public Renderer setColor(int red, int green, int blue) {
64 public Renderer setAlpha(int alpha) {
69 Renderer addPoint(OffsetPoint point) {
70 return addPoint(point.getX(), point.getY(), point.getZ());
73 public Renderer addPoints(OffsetPoint[] points) {
74 Renderer renderer = this;
75 for (OffsetPoint point : points) {
76 renderer = renderer.addPoint(point);
81 public Renderer addPoint(double x, double y, double z) {
90 public Renderer addPoint(double x, double y, double z, double u, double v) {
98 public void render() {
99 if (glMode == VertexFormat.DrawMode.QUADS) {
100 bufferBuilder.setCameraPosition((float) Camera.getX(), (float) Camera.getY(), (float) Camera.getZ());
106 private void pos(double x, double y, double z) {
107 bufferBuilder.vertex(matrixStack.peek().getPositionMatrix(), (float) x, (float) y, (float) z);
110 private void tex(double u, double v) {
111 bufferBuilder.texture((float) u, (float) v);
114 private void color() {
115 bufferBuilder.color(red / 255F, green / 255F, blue / 255F, alpha / 255F);
119 bufferBuilder.next();