From 0b4e84323cc9bb24d8a15bd551ef5a7b723f3fef Mon Sep 17 00:00:00 2001 From: ktyl Date: Sun, 3 Mar 2024 23:52:34 +0000 Subject: [PATCH] wip: receive key input --- src/main.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ef99cec..2da5b2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "gfx.hpp" #include "icosphere.hpp" @@ -45,6 +46,14 @@ #include "orbiter.hpp" #include "widget.hpp" +void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + if (key == GLFW_KEY_C && action == GLFW_PRESS) + { + std::cout << "lol!" << std::endl; + } +} + int main() { GLFWwindow* window = nullptr; @@ -54,9 +63,9 @@ int main() GLuint litProgram = compileShaderProgram("./frag_lit.glsl"); GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl"); + // set up scene Icosphere planet(0.2, 3, litProgram); - std::vector keplerianElements(6); keplerianElements[astro::semiMajorAxisIndex] = .75; keplerianElements[astro::eccentricityIndex] = .5; @@ -68,9 +77,18 @@ int main() Icosphere orbiterSphere(0.07, 2, litProgram); Orbiter orbiter(orbiterSphere, orbit, unlitProgram); + // register input + // TODO: init objects with a reference to the window so that they can register + // their own key inputs + glfwSetKeyCallback(window, keyCallback); + // Main loop while (!glfwWindowShouldClose(window)) { + // TODO: receive input from GLFW + glfwPollEvents(); + + // rendering glClearColor(0.2, 0.3, 0.3, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -79,7 +97,6 @@ int main() orbiter.render(time); glfwSwapBuffers(window); - glfwPollEvents(); } glfwTerminate();