From 3fdc6eb4f2cbeffce9b250beec4d3a2d52a3f534 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Wed, 6 Apr 2022 20:52:51 -0700 Subject: Work on moving infrastruture to this project --- source/main.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source/main.cpp') diff --git a/source/main.cpp b/source/main.cpp index b98d62b..8f61696 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -18,6 +18,14 @@ static void GlfwErrorCallback(int error, const char* description) { fprintf(stderr, "Glfw Error %d: %s\n", error, description); } +static void GlfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { + GLFWkeyboard* keyboard = glfwGetLastActiveKeyboard(); + if (keyboard) { + App* app = static_cast(glfwGetWindowUserPointer(window)); + app->HandleKey(keyboard, key, action); + } +} + int main() { if (!glfwInit()) { return -1; @@ -46,10 +54,18 @@ int main() { glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); #endif + App app; + GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui Command Palette Example", nullptr, nullptr); if (window == nullptr) { return -2; } + + glfwSetWindowUserPointer(window, &app); + + // Window callbacks are retained by ImGui GLFW backend + glfwSetKeyCallback(window, &GlfwKeyCallback); + glfwMakeContextCurrent(window); glfwSwapInterval(1); @@ -63,7 +79,7 @@ int main() { ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(glsl_version); - App app; + app.Init(); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -84,6 +100,7 @@ int main() { glfwSwapBuffers(window); } + app.Shutdown(); ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); -- cgit v1.2.3-70-g09d2