]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blob - src/main/java/com/irtimaled/bbor/client/renderers/RenderHelper.java
28af6b0446bfae12028c21c5330baed6a63f3e88
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / renderers / RenderHelper.java
1 package com.irtimaled.bbor.client.renderers;
2
3 import com.irtimaled.bbor.client.Camera;
4 import com.irtimaled.bbor.client.config.ConfigManager;
5 import com.mojang.blaze3d.platform.GlStateManager;
6 import com.mojang.blaze3d.systems.RenderSystem;
7 import net.minecraft.client.util.math.MatrixStack;
8 import net.minecraft.util.math.Quaternion;
9 import org.lwjgl.opengl.GL11;
10
11 public class RenderHelper {
12
13     public static void beforeRender() {
14         enableBlend();
15         GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
16         GL11.glEnable(GL11.GL_LINE_SMOOTH);
17         RenderSystem.disableCull();
18         enableDepthTest();
19         RenderSystem.depthMask(true);
20         RenderSystem.depthFunc(GL11.GL_LEQUAL);
21
22         if (ConfigManager.alwaysVisible.get()) {
23             RenderSystem.disableDepthTest();
24         }
25         RenderBatch.beginBatch();
26     }
27
28     public static void afterRender() {
29         RenderBatch.endBatch();
30         enableDepthTest();
31         RenderSystem.enableCull();
32         GL11.glDisable(GL11.GL_LINE_SMOOTH);
33         RenderSystem.setShaderColor(1, 1, 1, 1);
34     }
35
36     public static void beforeRenderFont(MatrixStack matrixStack, OffsetPoint offsetPoint) {
37         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
38         matrixStack.push();
39         polygonModeFill();
40         matrixStack.translate(offsetPoint.getX(), offsetPoint.getY() + 0.002D, offsetPoint.getZ());
41         // GL11.glNormal3f(0.0F, 1.0F, 0.0F);
42         matrixStack.multiply(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F));
43         matrixStack.multiply(new Quaternion(0.0F, 90.0F, 1.0F, 0.0F));
44         matrixStack.scale(-0.0175F, -0.0175F, 0.0175F);
45         enableTexture();
46         enableBlend();
47         GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
48
49         depthMaskTrue();
50     }
51
52     public static void afterRenderFont(MatrixStack matrixStack) {
53         disableTexture();
54         disableBlend();
55         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
56         matrixStack.pop();
57         enableDepthTest();
58     }
59
60 //    public static void disableLighting() {
61 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
62 //        GL11.glDisable(GL11.GL_LIGHTING);
63 //    }
64
65     public static void disableDepthTest() {
66         GlStateManager._disableDepthTest();
67     }
68
69     public static void enableDepthTest() {
70         GlStateManager._enableDepthTest();
71     }
72
73 //    public static void disableFog() {
74 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
75 //        GL11.glDisable(GL11.GL_FOG);
76 //    }
77
78     public static void disableBlend() {
79         GlStateManager._disableBlend();
80     }
81
82     public static void enableBlend() {
83         GlStateManager._enableBlend();
84     }
85
86 //    public static void disableAlphaTest() {
87 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
88 //        GL11.glDisable(GL32.GL_ALPHA_TEST);
89 //    }
90 //
91 //    public static void enableAlphaTest() {
92 //        RenderSystem.assertThread(RenderSystem::isOnRenderThread);
93 //        GL11.glEnable(GL11.GL_ALPHA_TEST);
94 //    }
95
96     public static void disableTexture() {
97         GlStateManager._disableTexture();
98     }
99
100     public static void enableTexture() {
101         GlStateManager._enableTexture();
102     }
103
104 //    public static void shadeModelSmooth() {
105 //        RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
106 //        GL11.glShadeModel(GL11.GL_SMOOTH);
107 //    }
108 //
109 //    public static void shadeModelFlat() {
110 //        RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
111 //        GL11.glShadeModel(GL11.GL_FLAT);
112 //    }
113
114 //    public static void enablePointSmooth() {
115 //        GL11.glEnable(GL11.GL_POINT_SMOOTH);
116 //    }
117
118     public static void lineWidth2() {
119         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
120         RenderSystem.lineWidth(2f);
121     }
122
123     public static void polygonModeLine() {
124         GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
125     }
126
127     public static void polygonModeFill() {
128         GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
129     }
130
131     public static void polygonOffsetMinusOne() {
132         GlStateManager._polygonOffset(-1.f, -1.f);
133     }
134
135     public static void enablePolygonOffsetLine() {
136         RenderSystem.assertThread(RenderSystem::isOnRenderThread);
137         GL11.glEnable(GL11.GL_POLYGON_OFFSET_LINE);
138     }
139
140     public static void depthMaskTrue() {
141         GlStateManager._depthMask(true);
142     }
143
144     public static void blendFuncGui() {
145         GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
146     }
147
148     public static void depthFuncAlways() {
149         GlStateManager._depthFunc(GL11.GL_ALWAYS);
150     }
151
152     public static void depthFuncLessEqual() {
153         GlStateManager._depthFunc(GL11.GL_LEQUAL);
154     }
155
156     public static void applyRegionalRenderOffset(MatrixStack matrixStack)
157     {
158
159         int regionX = (((int) Camera.getX()) >> 9) << 9;
160         int regionZ = (((int) Camera.getZ()) >> 9) << 9;
161
162         matrixStack.translate(regionX - Camera.getX(), -Camera.getY(),
163                 regionZ - Camera.getZ());
164     }
165
166 }