diff --git a/README.MD b/README.MD index c554ac7..d8b828f 100644 --- a/README.MD +++ b/README.MD @@ -45,6 +45,8 @@ java.base/sun.nio.ch=ALL-UNNAMED java.desktop/sun.awt.image=ALL-UNNAMED ``` +If you want to tweak your default window size, OpenGL context properties or other more advanced settings, check out the config file in `config/lwjgl3ify.cfg` after the first startup. + ## Server Install the mod jar in `mods/`, and download the `forgePatches` jar. Put the forgePatches jar in the same folder as your forge-universal and minecraft server jars. Lwjgl3ify also depends on GTNHMixins (), use at least version 2.1.10. diff --git a/src/main/java/me/eigenraven/lwjgl3ify/core/Config.java b/src/main/java/me/eigenraven/lwjgl3ify/core/Config.java index ae00bbe..7866e86 100644 --- a/src/main/java/me/eigenraven/lwjgl3ify/core/Config.java +++ b/src/main/java/me/eigenraven/lwjgl3ify/core/Config.java @@ -52,6 +52,18 @@ public class Config { public static boolean SHOW_JAVA_VERSION = true; public static boolean SHOW_LWJGL_VERSION = true; + public static int WINDOW_WIDTH = 854; + public static int WINDOW_HEIGHT = 480; + public static boolean WINDOW_START_MAXIMIZED = false, WINDOW_START_FOCUSED = true, WINDOW_START_ICONIFIED = false; + public static boolean WINDOW_DECORATED = true; + public static boolean OPENGL_DEBUG_CONTEXT = false; + public static boolean OPENGL_SRGB_CONTEXT = false; + public static boolean OPENGL_DOUBLEBUFFER = true; + public static boolean OPENGL_CONTEXT_NO_ERROR = false; + + public static String X11_CLASS_NAME = "minecraft"; + public static String COCOA_FRAME_NAME = "minecraft"; + public static String LWJGL3IFY_VERSION = Tags.VERSION; static void loadConfig() { @@ -66,6 +78,8 @@ public class Config { final File configFile = new File(configDir, "lwjgl3ify.cfg"); final Configuration config = new Configuration(configFile); final String CATEGORY_CORE = "core"; + final String CATEGORY_WINDOW = "window"; + final String CATEGORY_GLCONTEXT = "openglContext"; EXTENSIBLE_ENUMS.addAll(Arrays.asList(config.get( CATEGORY_CORE, "extensibleEnums", @@ -76,6 +90,48 @@ public class Config { "showJavaVersion", CATEGORY_CORE, SHOW_JAVA_VERSION, "Show java version in the debug hud"); SHOW_LWJGL_VERSION = config.getBoolean( "showLwjglVersion", CATEGORY_CORE, SHOW_LWJGL_VERSION, "Show lwjgl version in the debug hud"); + + WINDOW_WIDTH = config.getInt("width", CATEGORY_WINDOW, WINDOW_WIDTH, 64, 65536, "Default window width"); + WINDOW_HEIGHT = config.getInt("height", CATEGORY_WINDOW, WINDOW_HEIGHT, 64, 65536, "Default window height"); + WINDOW_START_MAXIMIZED = + config.getBoolean("maximized", CATEGORY_WINDOW, WINDOW_START_MAXIMIZED, "Start maximized?"); + WINDOW_START_FOCUSED = config.getBoolean("focused", CATEGORY_WINDOW, WINDOW_START_FOCUSED, "Start focused?"); + WINDOW_START_ICONIFIED = + config.getBoolean("iconified", CATEGORY_WINDOW, WINDOW_START_ICONIFIED, "Start iconified?"); + WINDOW_DECORATED = config.getBoolean( + "decorated", + CATEGORY_WINDOW, + WINDOW_DECORATED, + "Should the window have decorations (titlebar, border, close button)"); + X11_CLASS_NAME = config.getString( + "x11ClassName", + CATEGORY_WINDOW, + X11_CLASS_NAME, + "Linux-only - change the X11 class name, which is used by your window manager to identify the running application"); + COCOA_FRAME_NAME = config.getString( + "cocoaFrameName", + CATEGORY_WINDOW, + COCOA_FRAME_NAME, + "OSX-only - identifier used to save and restore the window position and size"); + + OPENGL_DEBUG_CONTEXT = config.getBoolean( + "debugContext", + CATEGORY_GLCONTEXT, + OPENGL_DEBUG_CONTEXT, + "Enable KHR_debug in the OpenGL context for advanced debugging capabilities"); + OPENGL_SRGB_CONTEXT = config.getBoolean( + "srgb", CATEGORY_GLCONTEXT, OPENGL_SRGB_CONTEXT, "Make the framebuffer use the sRGB color space"); + OPENGL_DOUBLEBUFFER = config.getBoolean( + "doubleBuffer", + CATEGORY_GLCONTEXT, + OPENGL_DOUBLEBUFFER, + "Make the framebuffer double-buffered (will cause visual artifacts if disabled)"); + OPENGL_CONTEXT_NO_ERROR = config.getBoolean( + "noError", + CATEGORY_GLCONTEXT, + OPENGL_CONTEXT_NO_ERROR, + "Enable GL_KHR_no_error to use faster driver code, but which can cause memory corruption in case of OpenGL errors"); + if (config.hasChanged()) { config.save(); } diff --git a/src/main/java/org/lwjglx/opengl/Display.java b/src/main/java/org/lwjglx/opengl/Display.java index 6a6a828..479bb70 100644 --- a/src/main/java/org/lwjglx/opengl/Display.java +++ b/src/main/java/org/lwjglx/opengl/Display.java @@ -2,12 +2,11 @@ package org.lwjglx.opengl; import static org.lwjgl.glfw.Callbacks.*; import static org.lwjgl.glfw.GLFW.*; -import static org.lwjgl.opengl.GL11.GL_FALSE; -import static org.lwjgl.opengl.GL11.GL_TRUE; import static org.lwjgl.system.MemoryUtil.NULL; import java.nio.ByteBuffer; import java.nio.IntBuffer; +import me.eigenraven.lwjgl3ify.core.Config; import org.lwjgl.glfw.*; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWCharCallback; @@ -115,14 +114,29 @@ public class Display { desktopDisplayMode = new DisplayMode(monitorWidth, monitorHeight, monitorBitPerPixel, monitorRefreshRate); glfwDefaultWindowHints(); - glfwWindowHint(GLFW_VISIBLE, GL_FALSE); - glfwWindowHint(GLFW_RESIZABLE, displayResizable ? GL_TRUE : GL_FALSE); + glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); - glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); - Window.handle = glfwCreateWindow(640, 480, windowTitle, NULL, NULL); - if (Window.handle == 0L) throw new IllegalStateException("Failed to create Display window"); + glfwWindowHint(GLFW_MAXIMIZED, Config.WINDOW_START_MAXIMIZED ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_FOCUSED, Config.WINDOW_START_FOCUSED ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_ICONIFIED, Config.WINDOW_START_ICONIFIED ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_DECORATED, Config.WINDOW_DECORATED ? GLFW_TRUE : GLFW_FALSE); + + glfwWindowHint(GLFW_SRGB_CAPABLE, Config.OPENGL_SRGB_CONTEXT ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_DOUBLEBUFFER, Config.OPENGL_DOUBLEBUFFER ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_CONTEXT_NO_ERROR, Config.OPENGL_CONTEXT_NO_ERROR ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, Config.OPENGL_DEBUG_CONTEXT ? GLFW_TRUE : GLFW_FALSE); + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, Config.OPENGL_DEBUG_CONTEXT ? GLFW_TRUE : GLFW_FALSE); + + glfwWindowHintString(GLFW_X11_CLASS_NAME, Config.X11_CLASS_NAME); + glfwWindowHintString(GLFW_COCOA_FRAME_NAME, Config.COCOA_FRAME_NAME); + + Window.handle = glfwCreateWindow(Config.WINDOW_WIDTH, Config.WINDOW_HEIGHT, windowTitle, NULL, NULL); + if (Window.handle == 0L) { + throw new IllegalStateException("Failed to create Display window"); + } Window.keyCallback = new GLFWKeyCallback() { @Override @@ -218,8 +232,6 @@ public class Display { displayFramebufferWidth = fbw.get(0); displayFramebufferHeight = fbh.get(0); - glfwSetWindowPos(Window.handle, (monitorWidth - mode.getWidth()) / 2, (monitorHeight - mode.getHeight()) / 2); - displayX = (monitorWidth - mode.getWidth()) / 2; displayY = (monitorHeight - mode.getHeight()) / 2; @@ -233,7 +245,6 @@ public class Display { } glfwSwapInterval(1); - glfwShowWindow(Window.handle); displayCreated = true; @@ -408,9 +419,7 @@ public class Display { public static void setResizable(boolean resizable) { displayResizable = resizable; - if (getWindow() != 0) { - glfwSetWindowAttrib(getWindow(), GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE); - } + // Ignore the request because why would you make the game window non-resizable } public static boolean isResizable() { diff --git a/src/main/java/org/lwjglx/opengl/DrawableGL.java b/src/main/java/org/lwjglx/opengl/DrawableGL.java index 33d256d..59d6244 100644 --- a/src/main/java/org/lwjglx/opengl/DrawableGL.java +++ b/src/main/java/org/lwjglx/opengl/DrawableGL.java @@ -31,6 +31,9 @@ */ package org.lwjglx.opengl; +import static org.lwjgl.glfw.GLFW.GLFW_FALSE; +import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE; +import static org.lwjgl.glfw.GLFW.glfwWindowHint; import static org.lwjgl.opengl.GL11.*; import org.lwjgl.glfw.GLFW; @@ -75,6 +78,7 @@ public class DrawableGL implements DrawableLWJGL { public ContextGL createSharedContext() throws LWJGLException { synchronized (GlobalLock.lock) { + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); long hiddenWindow = GLFW.glfwCreateWindow(16, 16, "MC - Shared Drawable", 0, this.context.glfwWindow); if (hiddenWindow == 0) { throw new LWJGLException("Couldn't create shared context hidden window");