-/* cubetwist, Copyright (c) 2016 Jamie Zawinski <jwz@jwz.org>
+/* cubetwist, Copyright (c) 2016-2017 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
"*suppressRotationAnimation: True\n" \
# define refresh_cube 0
+# define release_cube 0
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
int polys = 0;
int i, j;
- glPushMatrix();
glColor4fv (c->color);
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c->color);
if (c->next)
{
+ /* This leaves rotations on the prevailing matrix stack, but since
+ this is a tail-call, that's fine. Don't blow the matrix stack. */
glRotatef (c->rot.x, 1, 0, 0);
glRotatef (c->rot.y, 0, 1, 0);
glRotatef (c->rot.z, 0, 0, 1);
c->next->rot = c->rot;
polys += draw_cubes (mi, c->next);
}
- glPopMatrix();
+ check_gl_error("cubetwist");
return polys;
}
}
+static void free_cube (ModeInfo *mi);
+
ENTRYPOINT void
init_cube (ModeInfo *mi)
{
cube_configuration *bp;
int wire = MI_IS_WIREFRAME(mi);
- if (!bps) {
- bps = (cube_configuration *)
- calloc (MI_NUM_SCREENS(mi), sizeof (cube_configuration));
- if (!bps) {
- fprintf(stderr, "%s: out of memory\n", progname);
- exit(1);
- }
- }
+ MI_INIT (mi, bps, free_cube);
bp = &bps[MI_SCREEN(mi)];
glXSwapBuffers(dpy, window);
}
-ENTRYPOINT void
-release_cube (ModeInfo *mi)
+static void
+free_cube (ModeInfo *mi)
{
cube_configuration *bp = &bps[MI_SCREEN(mi)];
while (bp->cubes)