I have largely one major issue regarding GLFW window creation using LWJGL on Mac OSX. The jar-file is launched from the terminal using the following command:
java -XstartOnFirstThread -jar MyJar.jar
The problem is that the GLFW window appears behind the terminal window and is out of focus, even if you click on it. The graphics and audio of the window works perfectly (when the window is resized, for the graphics), but due to the GLFW window not being in focus no key-input can be registered. The key-input is instead being registered in the terminal window and key-input is rather important for my program.
A common answer floating around on especially the lwjgl forum is that AWT causes this issue. I have now ensured that no AWT object nor call what so ever exists in my code, but the issue remains the same. The standard active threads are the following:
main
Java Sound Event Dispatcher
MUSIC#assets/audio/music/menu.ogg
where "main" is the java main thread, "Java Sound Event Dispatcher" is probably something that has to do with javax.sound.sampled and "MUSIC#assets/audio/music/menu.ogg" is just a thread that reads data into jorbis where I have ensured that my code contains no references to anything in the AWT package. So it does not appear to exist any AWT-thread.
I have also tried both glfwWindowHint(GLFW_FOCUSED, GL_TRUE) and glfwFocusWindow(...), none of which works. I have also tried to add -Djava.awt.headless=true which just causes the terminal to output:
[...] mainbasesystem.local java[384] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
GLFW window creation code is as follows:
public static boolean initGLFW(boolean full) {
try{
glfwInit();
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
glfwWindowHint(GLFW_FOCUSED, GL_TRUE);
try{glfwDestroyWindow(window);} catch(Exception e){}
videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
window = glfwCreateWindow(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, TITLE, 0, 0);
glfwSetWindowPos(window, (videoMode.width()-VIEWPORT_WIDTH)/2, (videoMode.height()-VIEWPORT_HEIGHT)/2);
keyHandler = new KeyHandler();
glfwSetKeyCallback(window, keyHandler);
glfwSetWindowSizeCallback(window, windowSize);
glfwSetWindowIconifyCallback(window, windowIconification);
glfwSetInputMode(window, GLFW_CURSOR, (Options.cursorBound ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL));
try {
File icon16Path = new File("assets/icon16.png");
if(icon16Path.exists())
glfwSetWindowIcon(window, LWJGLFunc.createGLFWIcon("assets/icon16.png", "assets/icon32.png"));
} catch(Exception e) {
e.printStackTrace(Core.err);
}
glfwSwapInterval(0);
glfwMakeContextCurrent(window);
glfwShowWindow(window);
glfwFocusWindow(window);
return true;
} catch(Exception e){
e.printStackTrace(Core.err);
}
return false;
}
Everything works perfectly on Windows 7 and 8.1 (where Windows 8.1 is used on the same computer as Mac OSX).
Additional info:
- Mac OSX Yosemite 10.10.5
- LWJGL 3.2.0 (custom download with GLFW and STB)
- Also javacv and jorbis
How should this problem be solved?