我使用 LWJGL,当我使用 glfwCreateWindow 时,它卡住了我的代码
I use LWJGL and when I use glfwCreateWindow it stuck my code
我是 LWJGL 的新手,不是 Java 的专家,但我想学习如何创建游戏。
我使用 Mac。当我 运行 我的代码卡在 glfwCreateWindow 时,我看了很多教程,但我无法修复它。
这里是出问题的代码:
private void init() {
if(!glfwInit()) {
System.err.println("ERROR: can't initialize GLFW");
}
glfwInit();
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
windowID = glfwCreateWindow(800, 600, "Window", 0, 0);
glfwMakeContextCurrent(windowID);
GL.createCapabilities();
glfwShowWindow(windowID);
}
这是我的全部代码:
private static Window instance = null;
private long windowID;
private Window() {}
public static Window get() {
if (instance == null) {
instance = new Window();
}
return instance;
}
public void run() {
init();
loop();
}
private void init() {
if(!glfwInit()) {
System.err.println("ERROR: can't initialize GLFW");
}
glfwInit();
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
windowID = glfwCreateWindow(800, 600, "Window", 0, 0);
glfwMakeContextCurrent(windowID);
GL.createCapabilities();
glfwShowWindow(windowID);
}
private void loop() {
while(!glfwWindowShouldClose(windowID)) {
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(windowID);
glfwPollEvents();
}
}
}
我希望有人能帮助我(我也是 Whosebug 的新手)。
我只需要把
-XstartOnFirstThread
在 VM 参数中并且有效。
我是 LWJGL 的新手,不是 Java 的专家,但我想学习如何创建游戏。 我使用 Mac。当我 运行 我的代码卡在 glfwCreateWindow 时,我看了很多教程,但我无法修复它。
这里是出问题的代码:
private void init() {
if(!glfwInit()) {
System.err.println("ERROR: can't initialize GLFW");
}
glfwInit();
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
windowID = glfwCreateWindow(800, 600, "Window", 0, 0);
glfwMakeContextCurrent(windowID);
GL.createCapabilities();
glfwShowWindow(windowID);
}
这是我的全部代码:
private static Window instance = null;
private long windowID;
private Window() {}
public static Window get() {
if (instance == null) {
instance = new Window();
}
return instance;
}
public void run() {
init();
loop();
}
private void init() {
if(!glfwInit()) {
System.err.println("ERROR: can't initialize GLFW");
}
glfwInit();
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
windowID = glfwCreateWindow(800, 600, "Window", 0, 0);
glfwMakeContextCurrent(windowID);
GL.createCapabilities();
glfwShowWindow(windowID);
}
private void loop() {
while(!glfwWindowShouldClose(windowID)) {
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(windowID);
glfwPollEvents();
}
}
}
我希望有人能帮助我(我也是 Whosebug 的新手)。
我只需要把
-XstartOnFirstThread
在 VM 参数中并且有效。