Method to create and initialize GLFW window. @param config configuration object with basic window information
(final Configuration config)
| 82 | * @param config configuration object with basic window information |
| 83 | */ |
| 84 | protected void initWindow(final Configuration config) { |
| 85 | GLFWErrorCallback.createPrint(System.err).set(); |
| 86 | |
| 87 | if (!glfwInit()) { |
| 88 | throw new IllegalStateException("Unable to initialize GLFW"); |
| 89 | } |
| 90 | |
| 91 | decideGlGlslVersions(); |
| 92 | |
| 93 | glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
| 94 | handle = glfwCreateWindow(config.getWidth(), config.getHeight(), config.getTitle(), MemoryUtil.NULL, MemoryUtil.NULL); |
| 95 | |
| 96 | if (handle == MemoryUtil.NULL) { |
| 97 | throw new RuntimeException("Failed to create the GLFW window"); |
| 98 | } |
| 99 | |
| 100 | try (MemoryStack stack = MemoryStack.stackPush()) { |
| 101 | final IntBuffer pWidth = stack.mallocInt(1); // int* |
| 102 | final IntBuffer pHeight = stack.mallocInt(1); // int* |
| 103 | |
| 104 | glfwGetWindowSize(handle, pWidth, pHeight); |
| 105 | final GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor())); |
| 106 | glfwSetWindowPos(handle, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); |
| 107 | } |
| 108 | |
| 109 | glfwMakeContextCurrent(handle); |
| 110 | |
| 111 | GL.createCapabilities(); |
| 112 | |
| 113 | glfwSwapInterval(GLFW_TRUE); |
| 114 | |
| 115 | if (config.isFullScreen()) { |
| 116 | glfwMaximizeWindow(handle); |
| 117 | } else { |
| 118 | glfwShowWindow(handle); |
| 119 | } |
| 120 | |
| 121 | clearBuffer(); |
| 122 | renderBuffer(); |
| 123 | |
| 124 | glfwSetWindowSizeCallback(handle, new GLFWWindowSizeCallback() { |
| 125 | @Override |
| 126 | public void invoke(final long window, final int width, final int height) { |
| 127 | runFrame(); |
| 128 | } |
| 129 | }); |
| 130 | } |
| 131 | |
| 132 | private void decideGlGlslVersions() { |
| 133 | final boolean isMac = System.getProperty("os.name").toLowerCase().contains("mac"); |
no test coverage detected