Reputation: 45
I am new to LWJGL and not a pro at Java, but I want to learn how to create a game. I use a Mac. And when I run my code, it get stuck at glfwCreateWindow, I watched a lot of tutorial but I can't fix it.
Here is the code that make problems:
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);
}
And here is all my code:
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();
}
}
}
I hope someone can help me (an I am new to Stackoverflow too).
Upvotes: 0
Views: 219
Reputation: 45
I just need to put
-XstartOnFirstThread
in the VM argument and it work.
Upvotes: 1