Skip to content

Instantly share code, notes, and snippets.

@tail-call
Created April 2, 2018 04:23
Show Gist options
  • Save tail-call/9bdfa0c17988ba5acaf34352761b6194 to your computer and use it in GitHub Desktop.
Save tail-call/9bdfa0c17988ba5acaf34352761b6194 to your computer and use it in GitHub Desktop.
Scala LWJGL window template
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();
@tail-call
Copy link
Author

It isn't working actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment