aboutsummaryrefslogtreecommitdiff
path: root/source/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/main.cpp')
-rw-r--r--source/main.cpp19
1 files changed, 18 insertions, 1 deletions
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<App*>(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();