diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/InputLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/InputLayer.java index 04f73a7f..36f5a3b8 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/InputLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/InputLayer.java @@ -3,7 +3,6 @@ import net.smyler.smylib.gui.containers.FlexibleWidgetContainer; import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.Color; -import fr.thesmyler.smylibgui.util.RenderUtil; import fr.thesmyler.terramap.MapContext; import fr.thesmyler.terramap.input.KeyBindings; import net.smyler.smylib.gui.DrawContext; @@ -11,11 +10,9 @@ import net.smyler.terramap.util.geo.WebMercatorUtil; import net.smyler.smylib.math.Mat2d; import net.smyler.smylib.math.Vec2dMutable; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import org.lwjgl.input.Keyboard; import org.jetbrains.annotations.Nullable; +import org.lwjgl.input.Keyboard; import static java.lang.Math.*; import static net.smyler.smylib.SmyLib.getGameClient; @@ -71,11 +68,11 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous if(this.isRotating) { // If we are processing rotation input, draw pentagons at the corresponding spot - GlStateManager.pushMatrix(); - GlStateManager.translate(x + this.rotatePosition.x, y + this.rotatePosition.y, 0); + context.glState().pushViewMatrix(); + context.glState().translate(x + this.rotatePosition.x, y + this.rotatePosition.y); context.drawPolygon(Color.DARK_OVERLAY, ROTATION_POLYGON_VERTICES_OUTER); context.drawPolygon(Color.DARK_OVERLAY, ROTATION_POLYGON_VERTICES_INNER); - GlStateManager.popMatrix(); + context.glState().popViewMatrix(); } if (this.getMap().isDebugMode()) { diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapLayer.java index ec738946..04405a6b 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/MapLayer.java @@ -1,6 +1,8 @@ package fr.thesmyler.terramap.gui.widgets.map; import com.google.gson.JsonObject; +import net.smyler.smylib.gui.DrawContext; +import net.smyler.smylib.gui.GlState; import net.smyler.smylib.gui.containers.FlexibleWidgetContainer; import net.smyler.smylib.gui.containers.WidgetContainer; import net.smyler.smylib.gui.popups.Popup; @@ -200,10 +202,11 @@ void updateViewPorts() { * @param drawX the X coordinate the widget is supposed to be drawn at * @param drawY the Y coordinate the widget is supposed to be drawn at */ - protected void applyRotationGl(float drawX, float drawY) { - GlStateManager.translate(drawX + this.map.getWidth() / 2, drawY + this.map.getHeight() / 2, 0); - GlStateManager.rotate(this.rotation, 0, 0, 1); - GlStateManager.translate(-this.renderSpaceDimensionsHalf.x, -this.renderSpaceDimensionsHalf.y, 0); + protected void applyRotationGl(DrawContext context, float drawX, float drawY) { + GlState gl = context.glState(); + gl.translate(drawX + this.map.getWidth() / 2, drawY + this.map.getHeight() / 2); + gl.rotate(this.rotation); + gl.translate(-this.renderSpaceDimensionsHalf.x, -this.renderSpaceDimensionsHalf.y); } /** diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/DistortionLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/DistortionLayer.java index 5c193f6c..592fd752 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/DistortionLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/DistortionLayer.java @@ -13,7 +13,6 @@ import net.smyler.smylib.math.Vec2dReadOnly; import net.buildtheearth.terraplusplus.projection.GeographicProjection; import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; -import net.minecraft.client.renderer.GlStateManager; import static net.smyler.smylib.SmyLib.getGameClient; @@ -41,8 +40,8 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous GeographicProjection projection = TerramapClientContext.getContext().getProjection(); if(projection == null) return; map.getProfiler().startSection("layer-distortion"); - GlStateManager.pushMatrix(); - this.applyRotationGl(x, y); + context.glState().pushViewMatrix(); + this.applyRotationGl(context, x, y); double maxX = this.renderSpaceDimensions.x(); double maxY = this.renderSpaceDimensions.y(); @@ -64,8 +63,8 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous context.drawRectangle(x + dx, y + dy, x + dx + res, y + dy + res, color); } } - - GlStateManager.popMatrix(); + + context.glState().popViewMatrix(); map.getProfiler().endSection(); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java index 041876c1..0d11f6f2 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/McChunksLayer.java @@ -29,7 +29,6 @@ import net.smyler.smylib.math.Vec2dReadOnly; import net.buildtheearth.terraplusplus.projection.GeographicProjection; import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; -import net.minecraft.client.renderer.GlStateManager; import static net.smyler.smylib.SmyLib.getGameClient; import static net.smyler.smylib.math.Math.clamp; @@ -163,8 +162,8 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous return; } - GlStateManager.pushMatrix(); - this.applyRotationGl(x, y); + context.glState().pushViewMatrix(); + this.applyRotationGl(context, x, y); float size = 1f; @@ -185,7 +184,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous } this.cache.cycle(); - GlStateManager.popMatrix(); + context.glState().popViewMatrix(); map.getProfiler().endSection(); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java index 2823cb2d..17529db2 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RasterMapLayer.java @@ -22,7 +22,6 @@ import net.smyler.smylib.math.Vec2dMutable; import net.smyler.smylib.math.Vec2dReadOnly; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.profiler.Profiler; import net.minecraft.util.ResourceLocation; @@ -77,7 +76,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous profiler.startSection("render-raster-layer_" + tiledMap.getId()); - GlStateManager.pushMatrix(); + context.glState().pushViewMatrix(); float widthViewPort = this.getWidth(); float heightViewPort = this.getHeight(); double zoom = this.getMap().getController().getZoom(); @@ -87,7 +86,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous Vec2dImmutable xvec = rotationMatrix.line1(); Vec2dImmutable yvec = rotationMatrix.line2(); - this.applyRotationGl(x, y); + this.applyRotationGl(context, x, y); Vec2dReadOnly upperLeft = this.getUpperLeftRenderCornerPositionInMercatorSpace(); @@ -286,7 +285,7 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous this.lastNeededTiles.forEach(RasterTile::cancelTextureLoading); this.lastNeededTiles = neededTiles; - GlStateManager.popMatrix(); + context.glState().popViewMatrix(); profiler.endSection(); } diff --git a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RenderingDeltaPreviewLayer.java b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RenderingDeltaPreviewLayer.java index 6b05a0b4..88baaacc 100644 --- a/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RenderingDeltaPreviewLayer.java +++ b/forge/src/main/java/fr/thesmyler/terramap/gui/widgets/map/layer/RenderingDeltaPreviewLayer.java @@ -11,7 +11,6 @@ import net.smyler.terramap.util.geo.GeoPointMutable; import net.smyler.smylib.math.Vec2dMutable; import net.smyler.smylib.math.Vec2dReadOnly; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.profiler.Profiler; public class RenderingDeltaPreviewLayer extends MapLayer { @@ -40,13 +39,13 @@ public void draw(DrawContext context, float x, float y, float mouseX, float mous float height = this.getHeight(); this.getLocationPositionInRenderSpace(this.realCenterPosition, this.realCenter); - GlStateManager.pushMatrix(); - this.applyRotationGl(x, y); + context.glState().pushViewMatrix(); + this.applyRotationGl(context, x, y); context.drawStrokeLine(Color.RED, 2f, this.renderSpaceHalfDimensions.x(), this.renderSpaceHalfDimensions.y(), this.realCenterPosition.x, this.renderSpaceHalfDimensions.y(), this.realCenterPosition.x, this.realCenterPosition.y); - GlStateManager.popMatrix(); + context.glState().popViewMatrix(); float centerHole = 10; float linesWidth = 1f; diff --git a/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java b/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java index b8673c99..28129bcc 100644 --- a/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java +++ b/smylib/core/src/main/java/net/smyler/smylib/gui/GlState.java @@ -16,4 +16,14 @@ public interface GlState { void disableColorLogic(); + void pushViewMatrix(); + + void rotate(double angle); + + void translate(double x, double y); + + void scale(double x, double y); + + void popViewMatrix(); + } diff --git a/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java b/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java index c884d7ef..5649d9b7 100644 --- a/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java +++ b/smylib/forge/src/main/java/net/smyler/smylib/gui/LwjglState.java @@ -78,4 +78,29 @@ public void disableColorLogic() { GlStateManager.disableColorLogic(); } + @Override + public void pushViewMatrix() { + GlStateManager.pushMatrix(); + } + + @Override + public void rotate(double angle) { + GlStateManager.rotate((float)angle, 0, 0, 1f); + } + + @Override + public void translate(double x, double y) { + GlStateManager.translate(x, y, 0); + } + + @Override + public void scale(double x, double y) { + GlStateManager.scale(x, y, 1d); + } + + @Override + public void popViewMatrix() { + GlStateManager.popMatrix(); + } + }