-/* 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
"*wireframe: False \n" \
"*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;
}
reshape_cube (ModeInfo *mi, int width, int height)
{
GLfloat h = (GLfloat) height / (GLfloat) width;
+ int y = 0;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width;
+ y = -height/2;
+ h = height / (GLfloat) width;
+ }
- glViewport (0, 0, (GLint) width, (GLint) height);
+ glViewport (0, y, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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);
bp = &bps[MI_SCREEN(mi)];
}
ENTRYPOINT void
-release_cube (ModeInfo *mi)
+free_cube (ModeInfo *mi)
{
cube_configuration *bp = &bps[MI_SCREEN(mi)];
while (bp->cubes)