From 065c89e902b0d8f813195b636021313ec9dee3a1 Mon Sep 17 00:00:00 2001 From: karl Date: Fri, 13 Dec 2019 13:50:02 +0100 Subject: [PATCH] Add ESC key callback for closing --- main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.cpp b/main.cpp index 4410663..227d1de 100644 --- a/main.cpp +++ b/main.cpp @@ -32,6 +32,12 @@ private: float gravityAmount; }; +static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) + glfwSetWindowShouldClose(window, GLFW_TRUE); +} + int main() { World *world = World::createWorld(); world->registerSystem(new GravitySystem(-9.8f)); @@ -61,6 +67,8 @@ int main() { /* Make the window's context current */ glfwMakeContextCurrent(window); + glfwSetKeyCallback(window, key_callback); + /* Loop until the user closes the window */ while (!glfwWindowShouldClose(window)) { /* Render here */