Completely fixed monitor size is 0x0 (Forge mouse input should work rn)

This commit is contained in:
khanhduytran0 committed 2021-02-21 07:44:51 +07:00
1 parent 39b21f6380
commit d4b962ae75
5 files changed
+45 -40

No files matched your search

+9 -3
View File
@@ -73,8 +73,14 @@ public class HelloWorld {
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
System.out.println("Actual width=" + vidmode.width() + ", height=" + vidmode.height());
System.out.println("MONITOR SPEC");
System.out.println("width=" + vidmode.width());
System.out.println("height=" + vidmode.height());
System.out.println("red=" + vidmode.redBits());
System.out.println("green=" + vidmode.greenBits());
System.out.println("blue=" + vidmode.blueBits());
System.out.println("refresh=" + vidmode.refreshRate());
// Center the window
glfwSetWindowPos(
@@ -135,4 +141,4 @@ public class HelloWorld {
new HelloWorld().run();
}
}
}
@@ -16,8 +16,7 @@ public class UIKit {
}
public static void callback_SurfaceViewController_launchMinecraft(int width, int height) {
GLFW.mGLFWWindowWidth = width;
GLFW.mGLFWWindowHeight = height;
GLFW.internalChangeMonitorSize(width, height);
CallbackBridge.mouseX = width / 2;
CallbackBridge.mouseY = height / 2;
PLaunchApp.launchMinecraft();
+12 -14
View File
@@ -517,19 +517,11 @@ public class GLFW
mGLFWVideoMode = new GLFWVidMode(ByteBuffer.allocateDirect(GLFWVidMode.SIZEOF));
/*
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.WIDTH, mGLFWWindowWidth);
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.HEIGHT, mGLFWWindowHeight);
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.REDBITS, 8);
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.GREENBITS, 8);
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.BLUEBITS, 8);
memPutInt(mGLFWVideoMode.address() + mGLFWVideoMode.REFRESHRATE, 60);
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.REDBITS, 8);
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.GREENBITS, 8);
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.BLUEBITS, 8);
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.REFRESHRATE, 60);
*/
GLFWVidMode.WIDTH = mGLFWWindowWidth;
GLFWVidMode.HEIGHT = mGLFWWindowHeight;
GLFWVidMode.REDBITS = GLFWVidMode.GREENBITS = GLFWVidMode.BLUEBITS = 8;
GLFWVidMode.REFRESHRATE = 60;
// A way to generate key code names
Field[] thisFieldArr = GLFW.class.getFields();
try {
@@ -618,6 +610,13 @@ public class GLFW
return GLFW;
}
public static void internalChangeMonitorSize(int width, int height) {
mGLFWWindowWidth = width;
mGLFWWindowHeight = height;
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.WIDTH, mGLFWWindowWidth);
memPutInt(mGLFWVideoMode.address() + (long) mGLFWVideoMode.HEIGHT, mGLFWWindowHeight);
}
public static GLFWWindowProperties internalGetWindow(long window) {
GLFWWindowProperties win = mGLFWWindowMap.get(window);
if (win == null) {
@@ -1111,8 +1110,7 @@ public class GLFW
break;
case CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE:
case CallbackBridge.EVENT_TYPE_WINDOW_SIZE:
mGLFWWindowWidth = dataArr[1];
mGLFWWindowHeight = dataArr[2];
internalChangeMonitorSize(dataArr[1], dataArr[2]);
glfwSetWindowSize(ptr, mGLFWWindowWidth, mGLFWWindowHeight);
if (dataArr[0] == CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE && mGLFWFramebufferSizeCallback != null) {
mGLFWFramebufferSizeCallback.invoke(ptr, mGLFWWindowWidth, mGLFWWindowHeight);
@@ -49,13 +49,13 @@ public class GLFWVidMode extends Struct {
public static final int ALIGNOF;
/** The struct member offsets. */
public static /* final */ int
WIDTH,
HEIGHT,
REDBITS,
GREENBITS,
BLUEBITS,
REFRESHRATE;
public static final int
WIDTH,
HEIGHT,
REDBITS,
GREENBITS,
BLUEBITS,
REFRESHRATE;
static {
Layout layout = __struct(
@@ -69,6 +69,13 @@ public class GLFWVidMode extends Struct {
SIZEOF = layout.getSize();
ALIGNOF = layout.getAlignment();
WIDTH = layout.offsetof(0);
HEIGHT = layout.offsetof(1);
REDBITS = layout.offsetof(2);
GREENBITS = layout.offsetof(3);
BLUEBITS = layout.offsetof(4);
REFRESHRATE = layout.offsetof(5);
}
/**
@@ -129,17 +136,17 @@ public class GLFWVidMode extends Struct {
// -----------------------------------
/** Unsafe version of {@link #width}. */
public static int nwidth(long struct) { return WIDTH; }
public static int nwidth(long struct) { return UNSAFE.getInt(null, struct + GLFWVidMode.WIDTH); }
/** Unsafe version of {@link #height}. */
public static int nheight(long struct) { return HEIGHT; }
public static int nheight(long struct) { return UNSAFE.getInt(null, struct + GLFWVidMode.HEIGHT); }
/** Unsafe version of {@link #redBits}. */
public static int nredBits(long struct) { return REDBITS; }
public static int nredBits(long struct) { return 8; } // UNSAFE.getInt(null, struct + GLFWVidMode.REDBITS); }
/** Unsafe version of {@link #greenBits}. */
public static int ngreenBits(long struct) { return GREENBITS; }
public static int ngreenBits(long struct) { return 8; } // UNSAFE.getInt(null, struct + GLFWVidMode.GREENBITS); }
/** Unsafe version of {@link #blueBits}. */
public static int nblueBits(long struct) { return BLUEBITS; }
public static int nblueBits(long struct) { return 8; } // UNSAFE.getInt(null, struct + GLFWVidMode.BLUEBITS); }
/** Unsafe version of {@link #refreshRate}. */
public static int nrefreshRate(long struct) { return REFRESHRATE; }
public static int nrefreshRate(long struct) { return 60; } // UNSAFE.getInt(null, struct + GLFWVidMode.REFRESHRATE); }
// -----------------------------------
@@ -194,4 +201,4 @@ public class GLFWVidMode extends Struct {
}
}
}
@@ -72,16 +72,11 @@ public class Display {
static {
Sys.initialize(); // init using dummy sys method
GLFWVidMode.WIDTH = GLFW.mGLFWWindowWidth;
GLFWVidMode.HEIGHT = GLFW.mGLFWWindowHeight;
long monitor = glfwGetPrimaryMonitor();
GLFWVidMode vidmode = glfwGetVideoMode(monitor);
int monitorWidth = displayWidth = displayFramebufferWidth = GLFW.mGLFWWindowWidth;
// vidmode.width();
int monitorHeight = displayHeight = displayFramebufferHeight = GLFW.mGLFWWindowHeight;
// vidmode.height();
int monitorWidth = displayWidth = displayFramebufferWidth = vidmode.width();
int monitorHeight = displayHeight = displayFramebufferHeight = vidmode.height();
int monitorBitPerPixel = vidmode.redBits() + vidmode.greenBits() + vidmode.blueBits();
int monitorRefreshRate = vidmode.refreshRate();