Issue
So, I am pretty new to LWJGL and GLFW, and I'm following a tutorial. I'm on MacOS Big Sur 11.5.2 the window does stay open but crashes immediately and doesn't show. Anyone know why this is happening? Tutorial: click here LWJGL Version: 3.2.2 JDK: JavaSE-1.8
Window.java:
package com.bmc.voxel3d;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
public class Window {
private int width, height;
private String title;
private long window;
public Window(int width, int height, String title) {
this.width = width;
this.height = height;
this.title = title;
}
public void create() {
if(!GLFW.glfwInit()) {
System.out.println("ERROR: Didn't initialize GLFW.");
return;
}
window = GLFW.glfwCreateWindow(width, height, title, 0, 0);
if(window == 0) {
System.out.println("ERROR: Could not make window.");
return;
}
GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
GLFW.glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height / 2));
GLFW.glfwShowWindow(window);
}
}
and Main.java:
package com.bmc.minecraft;
import com.bmc.voxel3d.Window;
public class Main implements Runnable{
public Thread game;
public static Window window;
public static final int WIDTH = 854, HEIGHT = 480;
public void start() {
game = new Thread(this, "game");
game.start();
}
public static void init() {
System.out.println("Initializing Game!");
window = new Window(WIDTH, HEIGHT, "Game");
window.create();
}
public void run() {
init();
while(true) {
update();
render();
}
}
private void update() {
System.out.println("Updating Game!");
}
private void render() {
System.out.println("Rendering Game!");
}
public static void main(String[] args){
new Main().start();
}
}
Also, I have -XstartOnFirstThread in the Run Configuration Eclipse 2019
Solution
I assume that you mean that the window is not responding to user input.
The solution is fairly simple, instead of true
in the game loop, you need to put !glfwWindowShouldClose(window)
, which will tell GLFW that it should close when the x button is pressed.
Answered By - Xenon