LWJGL 3 - GLFW Window 崩溃
LWJGL 3 - GLFW Window crash
所以,我是 LWJGL 和 GLFW 的新手,我正在学习教程。我在 MacOS Big Sur 11.5.2 上 window 确实 保持打开状态但立即崩溃并且不显示。有人知道为什么会这样吗?教程: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
我假设你的意思是 window 没有响应用户输入。
解决方案相当简单,您需要在游戏循环中放置 !glfwWindowShouldClose(window)
而不是 true
,这将告诉 GLFW 在按下 x 按钮时它应该关闭。
所以,我是 LWJGL 和 GLFW 的新手,我正在学习教程。我在 MacOS Big Sur 11.5.2 上 window 确实 保持打开状态但立即崩溃并且不显示。有人知道为什么会这样吗?教程: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
我假设你的意思是 window 没有响应用户输入。
解决方案相当简单,您需要在游戏循环中放置 !glfwWindowShouldClose(window)
而不是 true
,这将告诉 GLFW 在按下 x 按钮时它应该关闭。