From 35a094792d28eaf31bcf0502746e211685d7573e Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Mon, 28 Oct 2024 11:42:38 -0400 Subject: press q to quit --- balls.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/balls.c b/balls.c index 7594eb7..48fc430 100644 --- a/balls.c +++ b/balls.c @@ -24,6 +24,7 @@ #define VMAX_INIT 0.1 /* Maximum initial velocity. */ enum { WIDTH = 640, HEIGHT = 480 }; +enum { KEY_QUIT = 'q' }; enum { NBALLS = 8, CIRCLE_POINTS = 16+2, /* +2 for center point and last point which overlaps with first point. */ @@ -40,6 +41,7 @@ void configureSharedData(void); void setKernelArgs(void); void display(void); void reshape(int w, int h); +void keyboard(unsigned char key, int x, int y); void move(void); void collideWalls(void); void genVertices(void); @@ -71,6 +73,7 @@ main(int argc, char *argv[]) { glutDisplayFunc(display); glutReshapeFunc(reshape); + glutKeyboardFunc(keyboard); glutMainLoop(); @@ -305,6 +308,12 @@ reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); } +void +keyboard(unsigned char key, int x, int y) { + if (key == KEY_QUIT) + glutDestroyWindow(glutGetWindow()); +} + void move(void) { size_t size; -- cgit v1.2.3