Created
April 2, 2018 04:23
-
-
Save tail-call/9bdfa0c17988ba5acaf34352761b6194 to your computer and use it in GitHub Desktop.
Scala LWJGL window template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.lwjgl.Version | |
| import org.lwjgl.glfw._ | |
| import org.lwjgl.opengl.GL | |
| println("LWJGL Version "+ Version.getVersion() +" is working.") | |
| // Print to console on error | |
| GLFW.glfwSetErrorCallback( | |
| GLFWErrorCallback.createPrint(System.err) | |
| ) | |
| // Initialize GL | |
| if (!GLFW.glfwInit()) { | |
| throw new IllegalStateException("Unable to initialize GLFW") | |
| } | |
| val window = GLFW.glfwCreateWindow(640, 480, "Simple example", 0, 0) | |
| if (window == 0) { | |
| GLFW.glfwTerminate() | |
| throw new RuntimeException("Failed to create the GLFW window") | |
| } | |
| // Keypress callback | |
| object keyCallback extends GLFWKeyCallback { | |
| def invoke(window: Long, key: Int, scancode: Int, action: Int, mods: Int) { | |
| if (key == GLFW.GLFW_KEY_ESCAPE && action == GLFW.GLFW_PRESS) { | |
| GLFW.glfwSetWindowShouldClose(window, true); | |
| } | |
| } | |
| } | |
| GLFW.glfwSetKeyCallback(window, keyCallback) | |
| // Create OpenGL context | |
| GLFW.glfwMakeContextCurrent(window); | |
| GL.createCapabilities(); | |
| // Event loop | |
| while (!GLFW.glfwWindowShouldClose(window)) { | |
| val time = GLFW.glfwGetTime() | |
| GLFW.glfwSwapBuffers(window) | |
| GLFW.glfwPollEvents() | |
| } | |
| // Window closed, shutting down | |
| GLFW.glfwDestroyWindow(window); | |
| keyCallback.free(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It isn't working actually.