summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2005-08-09 15:13:32 +0000
committerBrian Paul <[email protected]>2005-08-09 15:13:32 +0000
commita1a6fa2fa18c4982aa8151042df7d04551e47981 (patch)
tree945e9e18a844247c8bc3dcc2a1e2ae1c608fd50a
parentecde87054c48cc8c92c118a6efa848516bf0bf1c (diff)
free display lists and destroy window upon exit
-rw-r--r--progs/demos/gears.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/progs/demos/gears.c b/progs/demos/gears.c
index fc797eb904c..679fac44893 100644
--- a/progs/demos/gears.c
+++ b/progs/demos/gears.c
@@ -26,6 +26,7 @@
static GLint T0 = 0;
static GLint Frames = 0;
static GLint autoexit = 0;
+static GLint win = 0;
/**
@@ -164,6 +165,15 @@ static GLint gear1, gear2, gear3;
static GLfloat angle = 0.0;
static void
+cleanup(void)
+{
+ glDeleteLists(gear1, 1);
+ glDeleteLists(gear2, 1);
+ glDeleteLists(gear3, 1);
+ glutDestroyWindow(win);
+}
+
+static void
draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -198,16 +208,18 @@ draw(void)
Frames++;
{
- GLint t = glutGet(GLUT_ELAPSED_TIME);
- if (t - T0 >= 5000) {
- GLfloat seconds = (t - T0) / 1000.0;
- GLfloat fps = Frames / seconds;
- printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
- T0 = t;
- Frames = 0;
- if ((t >= 999.0 * autoexit) && (autoexit))
- exit(0);
- }
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ if (t - T0 >= 5000) {
+ GLfloat seconds = (t - T0) / 1000.0;
+ GLfloat fps = Frames / seconds;
+ printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
+ T0 = t;
+ Frames = 0;
+ if ((t >= 999.0 * autoexit) && (autoexit)) {
+ cleanup();
+ exit(0);
+ }
+ }
}
}
@@ -239,6 +251,7 @@ key(unsigned char k, int x, int y)
view_rotz -= 5.0;
break;
case 27: /* Escape */
+ cleanup();
exit(0);
break;
default:
@@ -352,7 +365,7 @@ int main(int argc, char *argv[])
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
- glutCreateWindow("Gears");
+ win = glutCreateWindow("Gears");
init(argc, argv);
glutDisplayFunc(draw);