【发布时间】:2021-10-17 22:06:35
【问题描述】:
所以,我对 LWJGL 和 GLFW 还是很陌生,我正在学习教程。我在 MacOS Big Sur 11.5.2 上,窗口确实保持打开状态,但立即崩溃并且不显示。有谁知道为什么会这样?教程:click here LWJGL 版本: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);
}
}
和 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();
}
}
另外,我在运行配置中有 -XstartOnFirstThread 日食 2019
【问题讨论】: