1 package com.irtimaled.bbor.client.renderers;
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 net.minecraft.util.math.Vec3d;
10 import org.lwjgl.opengl.GL11;
12 public class RenderHelper {
14 public static void beforeRender() {
16 GlStateManager._blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
17 GL11.glEnable(GL11.GL_LINE_SMOOTH);
18 RenderSystem.disableCull();
20 RenderSystem.depthMask(true);
21 RenderSystem.depthFunc(GL11.GL_LEQUAL);
23 if (ConfigManager.alwaysVisible.get()) {
24 RenderSystem.disableDepthTest();
26 RenderBatch.beginBatch();
29 public static void afterRender() {
30 RenderBatch.endBatch();
32 RenderSystem.enableCull();
33 GL11.glDisable(GL11.GL_LINE_SMOOTH);
34 RenderSystem.setShaderColor(1, 1, 1, 1);
37 public static void beforeRenderFont(MatrixStack matrixStack, OffsetPoint offsetPoint) {
38 RenderSystem.assertThread(RenderSystem::isOnRenderThread);
41 matrixStack.translate(offsetPoint.getX(), offsetPoint.getY() + 0.002D, offsetPoint.getZ());
42 // GL11.glNormal3f(0.0F, 1.0F, 0.0F);
43 matrixStack.multiply(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F));
44 matrixStack.multiply(new Quaternion(0.0F, 90.0F, 1.0F, 0.0F));
45 matrixStack.scale(-0.0175F, -0.0175F, 0.0175F);
48 GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
53 public static void afterRenderFont(MatrixStack matrixStack) {
56 RenderSystem.assertThread(RenderSystem::isOnRenderThread);
61 // public static void disableLighting() {
62 // RenderSystem.assertThread(RenderSystem::isOnRenderThread);
63 // GL11.glDisable(GL11.GL_LIGHTING);
66 public static void disableDepthTest() {
67 GlStateManager._disableDepthTest();
70 public static void enableDepthTest() {
71 GlStateManager._enableDepthTest();
74 // public static void disableFog() {
75 // RenderSystem.assertThread(RenderSystem::isOnRenderThread);
76 // GL11.glDisable(GL11.GL_FOG);
79 public static void disableBlend() {
80 GlStateManager._disableBlend();
83 public static void enableBlend() {
84 GlStateManager._enableBlend();
87 // public static void disableAlphaTest() {
88 // RenderSystem.assertThread(RenderSystem::isOnRenderThread);
89 // GL11.glDisable(GL32.GL_ALPHA_TEST);
92 // public static void enableAlphaTest() {
93 // RenderSystem.assertThread(RenderSystem::isOnRenderThread);
94 // GL11.glEnable(GL11.GL_ALPHA_TEST);
97 public static void disableTexture() {
98 GlStateManager._disableTexture();
101 public static void enableTexture() {
102 GlStateManager._enableTexture();
105 // public static void shadeModelSmooth() {
106 // RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
107 // GL11.glShadeModel(GL11.GL_SMOOTH);
110 // public static void shadeModelFlat() {
111 // RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
112 // GL11.glShadeModel(GL11.GL_FLAT);
115 // public static void enablePointSmooth() {
116 // GL11.glEnable(GL11.GL_POINT_SMOOTH);
119 public static void lineWidth2() {
120 RenderSystem.assertThread(RenderSystem::isOnRenderThread);
121 RenderSystem.lineWidth(2f);
124 public static void polygonModeLine() {
125 GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
128 public static void polygonModeFill() {
129 GlStateManager._polygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
132 public static void polygonOffsetMinusOne() {
133 GlStateManager._polygonOffset(-1.f, -1.f);
136 public static void enablePolygonOffsetLine() {
137 RenderSystem.assertThread(RenderSystem::isOnRenderThread);
138 GL11.glEnable(GL11.GL_POLYGON_OFFSET_LINE);
141 public static void depthMaskTrue() {
142 GlStateManager._depthMask(true);
145 public static void blendFuncGui() {
146 GlStateManager._blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ZERO, GL11.GL_ONE);
149 public static void depthFuncAlways() {
150 GlStateManager._depthFunc(GL11.GL_ALWAYS);
153 public static void depthFuncLessEqual() {
154 GlStateManager._depthFunc(GL11.GL_LEQUAL);
157 public static void applyRegionalRenderOffset(MatrixStack matrixStack)
160 int regionX = (((int) Camera.getX()) >> 9) << 9;
161 int regionZ = (((int) Camera.getZ()) >> 9) << 9;
163 matrixStack.translate(regionX - Camera.getX(), -Camera.getY(),
164 regionZ - Camera.getZ());
168 * Compute hash code for vec3d
169 * @see Vec3d#hashCode()
176 public static long hashVec3d(double x, double y, double z) {
177 long l = Double.doubleToLongBits(x);
178 int i = (int)(l ^ l >>> 32);
179 l = Double.doubleToLongBits(y);
180 i = 31 * i + (int)(l ^ l >>> 32);
181 l = Double.doubleToLongBits(z);
182 i = 31 * i + (int)(l ^ l >>> 32);