diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
index 2f0cf13ac..328348564 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
@@ -29,6 +29,7 @@ import de.bixilon.minosoft.gui.rendering.modding.events.*
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
import de.bixilon.minosoft.gui.rendering.shader.Shader
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
+import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
import de.bixilon.minosoft.gui.rendering.system.opengl.OpenGLRenderSystem
import de.bixilon.minosoft.gui.rendering.system.window.BaseWindow
@@ -206,12 +207,9 @@ class RenderWindow(
private fun registerGlobalKeyCombinations() {
inputHandler.registerKeyCallback(KeyBindingsNames.DEBUG_POLYGON) {
- glPolygonMode(GL_FRONT_AND_BACK, if (it) {
- GL_LINE
- } else {
- GL_FILL
- })
- sendDebugMessage("Toggled polygon mode!")
+ val nextMode = it.decide(PolygonModes.LINE, PolygonModes.FILL)
+ renderSystem.polygonMode = nextMode
+ sendDebugMessage("Set polygon to: $nextMode")
}
inputHandler.registerKeyCallback(KeyBindingsNames.QUIT_RENDERING) { window.close() }
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/FaceTypes.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/FaceTypes.kt
new file mode 100644
index 000000000..cbaa787c5
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/FaceTypes.kt
@@ -0,0 +1,27 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.gui.rendering.system.base
+
+enum class FaceTypes {
+ FRONT_LEFT,
+ FRONT_RIGHT,
+ BACK_LEFT,
+ BACK_RIGHT,
+ FRONT,
+ BACK,
+ LEFT,
+ RIGHT,
+ FRONT_AND_BACK,
+ ;
+}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/PolygonModes.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/PolygonModes.kt
new file mode 100644
index 000000000..3549ce7b9
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/PolygonModes.kt
@@ -0,0 +1,21 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.gui.rendering.system.base
+
+enum class PolygonModes {
+ FILL,
+ LINE,
+ POINT,
+ ;
+}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt
index 6d4fee77a..6739d4f20 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt
@@ -49,6 +49,7 @@ interface RenderSystem {
var depth: DepthFunctions
var depthMask: Boolean
- fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer
+ var polygonMode: PolygonModes
+ fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt
index 6cb4a6747..87204296b 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt
@@ -113,6 +113,15 @@ class OpenGLRenderSystem(
field = value
}
+ override var polygonMode: PolygonModes = PolygonModes.FILL
+ set(value) {
+ if (field == value) {
+ return
+ }
+ glPolygonMode(FaceTypes.FRONT_AND_BACK.gl, value.gl)
+ field = value
+ }
+
override fun readPixels(start: Vec2i, end: Vec2i, type: PixelTypes): ByteBuffer {
val buffer: ByteBuffer = BufferUtils.createByteBuffer((end.x - start.x) * (end.y - start.y) * type.bytes)
glReadPixels(start.x, start.y, end.x, end.y, type.gl, GL_UNSIGNED_BYTE, buffer)
@@ -178,5 +187,31 @@ class OpenGLRenderSystem(
else -> throw IllegalArgumentException("OpenGL does not support pixel type: $this")
}
}
+
+ private val PolygonModes.gl: Int
+ get() {
+ return when (this) {
+ PolygonModes.FILL -> GL_FILL
+ PolygonModes.LINE -> GL_LINE
+ PolygonModes.POINT -> GL_POINT
+ else -> throw IllegalArgumentException("OpenGL does not support polygon mode: $this")
+ }
+ }
+
+ private val FaceTypes.gl: Int
+ get() {
+ return when (this) {
+ FaceTypes.FRONT_LEFT -> GL_FRONT_LEFT
+ FaceTypes.FRONT_RIGHT -> GL_FRONT_RIGHT
+ FaceTypes.BACK_LEFT -> GL_BACK_LEFT
+ FaceTypes.BACK_RIGHT -> GL_BACK_RIGHT
+ FaceTypes.FRONT -> GL_FRONT
+ FaceTypes.BACK -> GL_BACK
+ FaceTypes.LEFT -> GL_LEFT
+ FaceTypes.RIGHT -> GL_RIGHT
+ FaceTypes.FRONT_AND_BACK -> GL_FRONT_AND_BACK
+ else -> throw IllegalArgumentException("OpenGL does not face type: $this")
+ }
+ }
}
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt
index 8ebad417d..db1d0cb57 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt
@@ -18,7 +18,6 @@ import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.system.base.PixelTypes
import de.bixilon.minosoft.util.Util
-import de.bixilon.minosoft.util.logging.Log
import glm_.vec2.Vec2i
import java.awt.image.BufferedImage
import java.io.File
@@ -36,6 +35,10 @@ class ScreenshotTaker(
var i = 1
while (File(path).exists()) {
path = "${basePath}_${i++}.png"
+ if (i > 10) {
+ screenshotFail(StackOverflowError())
+ return
+ }
}
val width = renderWindow.window.size.x
@@ -63,7 +66,6 @@ class ScreenshotTaker(
val message = "§aScreenshot saved to §f${file.name}"
renderWindow.sendDebugMessage(message)
- Log.game(message)
} catch (exception: Exception) {
screenshotFail(exception)
}
@@ -73,7 +75,7 @@ class ScreenshotTaker(
}
}
- private fun screenshotFail(exception: Exception?) {
+ private fun screenshotFail(exception: Throwable?) {
exception?.printStackTrace()
renderWindow.sendDebugMessage("§cFailed to make a screenshot!")
}