commit 853c85033deae647c94b87865c023c6be59abc44
parent 2c8fcb8dd6e3b67ffebf51f4d0ca0c612cd428b6
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Mon, 17 Jul 2023 22:16:55 +0100
gl-asteroids: add joytick event detection
Diffstat:
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/gl-asteroids.cpp b/src/gl-asteroids.cpp
@@ -396,6 +396,21 @@ visual const& random_rock_visual(void)
return *rock_types[rtype];
}
+void joy_cb(int jid, int event)
+{
+ switch (event)
+ {
+ case GLFW_CONNECTED:
+ std::cout << 'J' << jid << ": CONNECTED\n";
+ return;
+ case GLFW_DISCONNECTED:
+ std::cout << 'J' << jid << ": DISCONNECTED\n";
+ return;
+ default:
+ std::cout << 'J' << jid << ": " << event << '\n';
+ }
+}
+
int main(int, char* argv[])
{
signed score = 0;
@@ -429,6 +444,7 @@ int main(int, char* argv[])
glfwInit();
w = glfwCreateWindow(window_size, window_size, argv[0], NULL, NULL);
+ glfwSetJoystickCallback(joy_cb);
int wx, wy;
glfwGetFramebufferSize(w, &wx, &wy);
std::cout << "x: " << wx << " y: " << wy << '\n';