From e6177e7f67e33e82fe30dbf4b56d66d203b7632d Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 25 Aug 2024 20:08:52 +0200 Subject: [PATCH] Fix remaining scissor box issues --- .../net/wurstclient/clickgui/ClickGui.java | 8 ++--- src/main/java/net/wurstclient/hud/TabGui.java | 33 ++++++++---------- .../navigator/NavigatorFeatureScreen.java | 13 ++----- .../navigator/NavigatorMainScreen.java | 5 ++- .../navigator/NavigatorNewKeybindScreen.java | 7 ++-- .../NavigatorRemoveKeybindScreen.java | 7 ++-- .../net/wurstclient/util/RenderUtils.java | 34 ++++++++++++------- 7 files changed, 46 insertions(+), 61 deletions(-) diff --git a/src/main/java/net/wurstclient/clickgui/ClickGui.java b/src/main/java/net/wurstclient/clickgui/ClickGui.java index 60aec0cc..e2881908 100644 --- a/src/main/java/net/wurstclient/clickgui/ClickGui.java +++ b/src/main/java/net/wurstclient/clickgui/ClickGui.java @@ -740,11 +740,7 @@ public final class ClickGui bufferBuilder.vertex(matrix, x4, y3, 0); BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderSystem.setShaderColor(1, 1, 1, 1); - context.enableScissor(x1, y3, x2, y2); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); + RenderUtils.enableScissor(context, x1, y3, x2, y2); matrixStack.push(); matrixStack.translate(x1, y4, 0); @@ -796,7 +792,7 @@ public final class ClickGui matrixStack.pop(); matrix = matrixStack.peek().getPositionMatrix(); - context.disableScissor(); + RenderUtils.disableScissor(context); } RenderSystem.enableBlend(); diff --git a/src/main/java/net/wurstclient/hud/TabGui.java b/src/main/java/net/wurstclient/hud/TabGui.java index 9c02d404..a094cfa2 100644 --- a/src/main/java/net/wurstclient/hud/TabGui.java +++ b/src/main/java/net/wurstclient/hud/TabGui.java @@ -23,7 +23,6 @@ import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; import net.wurstclient.Category; import net.wurstclient.Feature; @@ -130,27 +129,25 @@ public final class TabGui implements KeyPressListener if(tabGuiOtf.isHidden()) return; + // CURSED: TabGUI renders behind HackList without this + context.getVertexConsumers().draw(); + ClickGui gui = WurstClient.INSTANCE.getGui(); int txtColor = gui.getTxtColor(); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.disableCull(); matrixStack.push(); - Window sr = WurstClient.MC.getWindow(); int x = 2; int y = 23; - matrixStack.translate(x, y, 0); + matrixStack.translate(x, y, 100); drawBox(matrixStack, 0, 0, width, height); - double factor = sr.getScaleFactor(); - GL11.glScissor((int)(x * factor), - (int)((sr.getScaledHeight() - height - y) * factor), - (int)(width * factor), (int)(height * factor)); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, x, y, x + width, y + height); int textY = 1; @@ -164,8 +161,8 @@ public final class TabGui implements KeyPressListener txtColor, false); textY += 10; } - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_SCISSOR_TEST); + + RenderUtils.disableScissor(context); if(tabOpened) { @@ -178,10 +175,8 @@ public final class TabGui implements KeyPressListener matrixStack.translate(width + 2, 0, 0); drawBox(matrixStack, 0, 0, tab.width, tab.height); - GL11.glScissor((int)(tabX * factor), - (int)((sr.getScaledHeight() - tab.height - tabY) * factor), - (int)(tab.width * factor), (int)(tab.height * factor)); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, tabX, tabY, tabX + tab.width, + tabY + tab.height); int tabTextY = 1; for(int i = 0; i < tab.features.size(); i++) @@ -199,8 +194,8 @@ public final class TabGui implements KeyPressListener tabTextY, txtColor, false); tabTextY += 10; } - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_SCISSOR_TEST); + + RenderUtils.disableScissor(context); matrixStack.pop(); } diff --git a/src/main/java/net/wurstclient/navigator/NavigatorFeatureScreen.java b/src/main/java/net/wurstclient/navigator/NavigatorFeatureScreen.java index b797b791..70cfb2be 100644 --- a/src/main/java/net/wurstclient/navigator/NavigatorFeatureScreen.java +++ b/src/main/java/net/wurstclient/navigator/NavigatorFeatureScreen.java @@ -352,13 +352,7 @@ public final class NavigatorFeatureScreen extends NavigatorScreen bgx2, bgy2); drawBoxShadow(matrixStack, bgx1, bgy1, bgx2, bgy2); - // scissor box - RenderSystem.setShaderColor(1, 1, 1, 1); - context.enableScissor(bgx1, bgy1, bgx2, bgy3); - RenderSystem.setShader(ShaderProgramKeys.POSITION); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, bgx1, bgy1, bgx2, bgy3); // settings gui.setTooltip(""); @@ -498,10 +492,7 @@ public final class NavigatorFeatureScreen extends NavigatorScreen } GL11.glEnable(GL11.GL_BLEND); - // scissor box - context.disableScissor(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); + RenderUtils.disableScissor(context); // buttons below scissor box for(ClickableWidget button : Screens.getButtons(this)) diff --git a/src/main/java/net/wurstclient/navigator/NavigatorMainScreen.java b/src/main/java/net/wurstclient/navigator/NavigatorMainScreen.java index 21eac12b..8f00de2d 100644 --- a/src/main/java/net/wurstclient/navigator/NavigatorMainScreen.java +++ b/src/main/java/net/wurstclient/navigator/NavigatorMainScreen.java @@ -254,8 +254,7 @@ public final class NavigatorMainScreen extends NavigatorScreen if(!clickTimerRunning) hoveredFeature = -1; - RenderUtils.scissorBox(0, 59, width, height - 42); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, 0, 59, width, height - 42); for(int i = Math.max(-scroll * 3 / 20 - 3, 0); i < navigatorDisplayList .size(); i++) @@ -272,7 +271,7 @@ public final class NavigatorMainScreen extends NavigatorScreen featureY); } - GL11.glDisable(GL11.GL_SCISSOR_TEST); + RenderUtils.disableScissor(context); // tooltip if(tooltip != null) diff --git a/src/main/java/net/wurstclient/navigator/NavigatorNewKeybindScreen.java b/src/main/java/net/wurstclient/navigator/NavigatorNewKeybindScreen.java index 5da1a8fe..def75397 100644 --- a/src/main/java/net/wurstclient/navigator/NavigatorNewKeybindScreen.java +++ b/src/main/java/net/wurstclient/navigator/NavigatorNewKeybindScreen.java @@ -176,9 +176,7 @@ public class NavigatorNewKeybindScreen extends NavigatorScreen boolean noButtons = Screens.getButtons(this).isEmpty(); int bgy3 = bgy2 - (noButtons ? 0 : 24); - // scissor box - RenderUtils.scissorBox(bgx1, bgy1, bgx2, bgy3); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, bgx1, bgy1, bgx2, bgy3); // possible keybinds if(!choosingKey) @@ -233,8 +231,7 @@ public class NavigatorNewKeybindScreen extends NavigatorScreen } GL11.glEnable(GL11.GL_BLEND); - // scissor box - GL11.glDisable(GL11.GL_SCISSOR_TEST); + RenderUtils.disableScissor(context); // buttons below scissor box for(ClickableWidget button : Screens.getButtons(this)) diff --git a/src/main/java/net/wurstclient/navigator/NavigatorRemoveKeybindScreen.java b/src/main/java/net/wurstclient/navigator/NavigatorRemoveKeybindScreen.java index d17ca9c1..55ae47ae 100644 --- a/src/main/java/net/wurstclient/navigator/NavigatorRemoveKeybindScreen.java +++ b/src/main/java/net/wurstclient/navigator/NavigatorRemoveKeybindScreen.java @@ -148,9 +148,7 @@ public class NavigatorRemoveKeybindScreen extends NavigatorScreen boolean noButtons = Screens.getButtons(this).isEmpty(); int bgy3 = bgy2 - (noButtons ? 0 : 24); - // scissor box - RenderUtils.scissorBox(bgx1, bgy1, bgx2, bgy3); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderUtils.enableScissor(context, bgx1, bgy1, bgx2, bgy3); // possible keybinds hoveredKey = ""; @@ -204,8 +202,7 @@ public class NavigatorRemoveKeybindScreen extends NavigatorScreen } GL11.glEnable(GL11.GL_BLEND); - // scissor box - GL11.glDisable(GL11.GL_SCISSOR_TEST); + RenderUtils.disableScissor(context); // buttons below scissor box for(ClickableWidget button : Screens.getButtons(this)) diff --git a/src/main/java/net/wurstclient/util/RenderUtils.java b/src/main/java/net/wurstclient/util/RenderUtils.java index f89c361c..9dc19a5b 100644 --- a/src/main/java/net/wurstclient/util/RenderUtils.java +++ b/src/main/java/net/wurstclient/util/RenderUtils.java @@ -9,7 +9,6 @@ package net.wurstclient.util; import org.joml.Matrix4f; import org.joml.Vector3f; -import org.lwjgl.opengl.GL11; import com.mojang.blaze3d.systems.RenderSystem; @@ -34,18 +33,29 @@ public enum RenderUtils private static final Box DEFAULT_BOX = new Box(0, 0, 0, 1, 1, 1); - public static void scissorBox(int startX, int startY, int endX, int endY) + /** + * Enables a new scissor box with the given coordinates, while avoiding the + * strange side-effects of Minecraft's own enableScissor() method. + */ + public static void enableScissor(DrawContext context, int x1, int y1, + int x2, int y2) { - int width = endX - startX; - int height = endY - startY; - int bottomY = WurstClient.MC.currentScreen.height - endY; - double factor = WurstClient.MC.getWindow().getScaleFactor(); - - int scissorX = (int)(startX * factor); - int scissorY = (int)(bottomY * factor); - int scissorWidth = (int)(width * factor); - int scissorHeight = (int)(height * factor); - GL11.glScissor(scissorX, scissorY, scissorWidth, scissorHeight); + RenderSystem.setShaderColor(1, 1, 1, 1); + context.enableScissor(x1, y1, x2, y2); + RenderSystem.setShader(ShaderProgramKeys.POSITION); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + } + + /** + * Disables the current scissor box, while avoiding the strange side-effects + * of Minecraft's own disableScissor() method. + */ + public static void disableScissor(DrawContext context) + { + context.disableScissor(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); } public static void applyRegionalRenderOffset(MatrixStack matrixStack)