Add ESC key callback for closing

This commit is contained in:
karl 2019-12-13 13:50:02 +01:00
parent dce2418762
commit 065c89e902

View File

@ -32,6 +32,12 @@ private:
float gravityAmount; 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() { int main() {
World *world = World::createWorld(); World *world = World::createWorld();
world->registerSystem(new GravitySystem(-9.8f)); world->registerSystem(new GravitySystem(-9.8f));
@ -61,6 +67,8 @@ int main() {
/* Make the window's context current */ /* Make the window's context current */
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
/* Loop until the user closes the window */ /* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
/* Render here */ /* Render here */