From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / antmaze.c
index e0ba5456cffafb0c6684fd61fec249eadeabe2a1..229257b9576fc7680ab606e862ce8eabf6d8fa01 100644 (file)
  * tennessy@cs.ubc.ca
  */
 
-#if !defined( lint ) && !defined( SABER )
+#if 0
 static const char sccsid[] = "@(#)antmaze.c    5.01 2001/03/01 xlockmore";
 #endif
 
 #ifdef STANDALONE
 # define MODE_antmaze
 # define DEFAULTS      "*delay:                20000   \n"     \
-                       "*showFPS:      False   \n"
+                       "*showFPS:      False   \n" \
+                       "*fpsSolid:     True    \n"
 
 # define refresh_antmaze 0
+# define release_antmaze 0
 # include "xlockmore.h"                /* from the xscreensaver distribution */
 #else /* !STANDALONE */
 # include "xlock.h"            /* from the xlockmore distribution */
-
 #endif /* !STANDALONE */
 
+#ifdef HAVE_JWXYZ
+# include "jwxyz.h"
+#else
+# include <X11/Xlib.h>
+# include <GL/gl.h>
+# include <GL/glu.h>
+#endif
+
+#ifdef HAVE_JWZGLES
+# include "jwzgles.h"
+#endif /* HAVE_JWZGLES */
+
 #ifdef MODE_antmaze
 
 
+#include "sphere.h"
+#include "tube.h"
 #include "rotator.h"
 #include "gltrackball.h"
 
@@ -67,7 +82,7 @@ ENTRYPOINT ModeSpecOpt antmaze_opts =
 
 #ifdef USE_MODULES
 ModStruct   antmaze_description =
-{"antmaze", "init_antmaze", "draw_antmaze", "release_antmaze",
+{"antmaze", "init_antmaze", "draw_antmaze", NULL,
  "draw_antmaze", "change_antmaze", NULL, &antmaze_opts,
  1000, 1, 1, 1, 4, 1.0, "",
  "draws some ants", 0, NULL};
@@ -174,6 +189,7 @@ static const GLfloat position1[] = {-1.0, -5.0, 1.0, 1.0};
 /* filled sphere */
 static Bool mySphere(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
 
   if((quadObj = gluNewQuadric()) == 0)
@@ -181,7 +197,13 @@ static Bool mySphere(float radius)
   gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
   gluSphere(quadObj, radius, 16, 16);
   gluDeleteQuadric(quadObj);
-
+#else
+    glPushMatrix();
+    glScalef (radius, radius, radius);
+    glRotatef (90, 1, 0, 0);
+    unit_sphere (16, 16, False);
+    glPopMatrix();
+#endif
   return True;
 }
 
@@ -204,6 +226,7 @@ static Bool mySphere2(float radius)
 /* textured sphere */
 static Bool mySphereTex(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
   
   if((quadObj = gluNewQuadric()) == 0)
@@ -213,6 +236,13 @@ static Bool mySphereTex(float radius)
   gluQuadricNormals(quadObj, GLU_SMOOTH);
   gluSphere(quadObj, radius, 32, 16);
   gluDeleteQuadric(quadObj);
+#else
+    glPushMatrix();
+    glScalef (radius, radius, radius);
+    glRotatef (90, 1, 0, 0);
+    unit_sphere (32, 16, False);
+    glPopMatrix();
+#endif
 
   return True;
 }
@@ -220,6 +250,7 @@ static Bool mySphereTex(float radius)
 /* filled cone */
 static Bool myCone(float radius) 
 {
+#if 0
   GLUquadricObj *quadObj;
   
   if ((quadObj = gluNewQuadric()) == 0)
@@ -227,6 +258,12 @@ static Bool myCone(float radius)
   gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
   gluCylinder(quadObj, radius, 0, radius * 2, 8, 1);
   gluDeleteQuadric(quadObj);
+#else
+    cone (0, 0, 0,
+          0, 0, radius * 2,
+          radius, 0,
+          8, True, True, False);
+#endif
   return True;
 }
 
@@ -326,7 +363,7 @@ static void makeBrushedImage(antmazestruct *mp)
 }
 
 #if 0
-static void draw_wall(double x1, double z1, double x2, double z2) 
+static void draw_wall(ModeInfo *mi, double x1, double z1, double x2, double z2) 
 {
   float x = fabs(x2 - x1)/2.0;
 
@@ -342,6 +379,7 @@ static void draw_wall(double x1, double z1, double x2, double z2)
   glVertex3f(x2, 1.0, z2-0.25);
   glTexCoord2f(0.0, 0.25);
   glVertex3f(x1, 1.0, z1-0.25);
+  mi->polygon_count++;
 
   /* draw sides */
   glNormal3f(0.0, 0.0, 1.0);
@@ -353,6 +391,7 @@ static void draw_wall(double x1, double z1, double x2, double z2)
   glVertex3f(x2, 1.0, z2+0.25);
   glTexCoord2f(0.0, 0.5);
   glVertex3f(x1, 1.0, z1+0.25);
+  mi->polygon_count++;
 
   glNormal3f(0.0, 0.0, -1.0);
   glTexCoord2f(0.0, 0.0);
@@ -363,6 +402,7 @@ static void draw_wall(double x1, double z1, double x2, double z2)
   glVertex3f(x2, 1.0, z2-0.25);
   glTexCoord2f(0.0, 0.5);
   glVertex3f(x1, 1.0, z1-0.25);
+  mi->polygon_count++;
 
   /* draw ends */
   glNormal3f(1.0, 0.0, 0.0);
@@ -374,6 +414,7 @@ static void draw_wall(double x1, double z1, double x2, double z2)
   glVertex3f(x2, 1.0, z2-0.25);
   glTexCoord2f(0.0, 0.5);
   glVertex3f(x2, 1.0, z2+0.25);
+  mi->polygon_count++;
 
   glNormal3f(-1.0, 0.0, 0.0);
   glTexCoord2f(0.0, 0.0);
@@ -384,12 +425,13 @@ static void draw_wall(double x1, double z1, double x2, double z2)
   glVertex3f(x1, 1.0, z1+0.25);
   glTexCoord2f(0.0, 0.5);
   glVertex3f(x1, 1.0, z1-0.25);
+  mi->polygon_count++;
 
   glEnd();
 }
 #endif
 
-static void draw_board(antmazestruct *mp) 
+static void draw_board(ModeInfo *mi, antmazestruct *mp) 
 {
 
   int i, j;
@@ -425,6 +467,7 @@ static void draw_board(antmazestruct *mp)
        glVertex3f(i+0.5, h, j-0.5);
        glTexCoord2f(0.0 + stf, 1.0 + stf);
        glVertex3f(i-0.5, h, j-0.5);
+        mi->polygon_count++;
 
        /* draw south face */
        if(j == 9 || !mp->board[mp->currentboard][j+1][i]) {
@@ -437,6 +480,7 @@ static void draw_board(antmazestruct *mp)
          glVertex3f(i+0.5, h, j+0.5);
          glTexCoord2f(0.0 + stf, h + stf);
          glVertex3f(i-0.5, h, j+0.5);
+          mi->polygon_count++;
        }
 
        /* draw north face */
@@ -450,6 +494,7 @@ static void draw_board(antmazestruct *mp)
          glVertex3f(i-0.5, h, j-0.5);
          glTexCoord2f(0.0 + stf, h + stf);
          glVertex3f(i+0.5, h, j-0.5);
+          mi->polygon_count++;
        }
 
        /* draw east face */
@@ -463,6 +508,7 @@ static void draw_board(antmazestruct *mp)
          glVertex3f(i+0.5, h, j-0.5);
          glTexCoord2f(0.0 + stf, h + stf);
          glVertex3f(i+0.5, h, j+0.5);
+          mi->polygon_count++;
        }
 
        /* draw west face */
@@ -476,6 +522,7 @@ static void draw_board(antmazestruct *mp)
          glVertex3f(i-0.5, h, j+0.5);
          glTexCoord2f(0.0 + stf, h + stf);
          glVertex3f(i-0.5, h, j-0.5);
+          mi->polygon_count++;
        }
       }
       else {
@@ -489,6 +536,7 @@ static void draw_board(antmazestruct *mp)
        glVertex3f(i+0.5, 0.0, j-0.5);
        glTexCoord2f(0.0, tx);
        glVertex3f(i-0.5, 0.0, j-0.5);
+        mi->polygon_count++;
       }
     }
   glEnd();
@@ -510,6 +558,7 @@ static void draw_board(antmazestruct *mp)
 /*       glVertex3f(1.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
 /*       glTexCoord2f(0.0, 1.5); */
 /*       glVertex3f(0.5, 0.0, BOARDSIZE + 1.0 + 0.2); */
+/*        mi->polygon_count++; */
 /*   } */
 
 /*   /\* destination *\/ */
@@ -521,6 +570,7 @@ static void draw_board(antmazestruct *mp)
 /*   glVertex3f(BOARDSIZE - 1.5, elevator, -0.5 - 0.2); */
 /*   glTexCoord2f(0.0, 1.5); */
 /*   glVertex3f(BOARDSIZE - 2.5, elevator, -0.5 - 0.2); */
+/*   mi->polygon_count++; */
 
 /*   glEnd(); */
 
@@ -538,6 +588,7 @@ static void draw_board(antmazestruct *mp)
 /*     glVertex3f(i+0.5 - stf, h+0.001, j-0.5 + stf); */
 /*     glTexCoord2f(0.0 + stf, 1.0 + stf); */
 /*     glVertex3f(i-0.5 + stf, h+0.001, j-0.5 + stf); */
+/*      mi->polygon_count++; */
 /*       } */
 /*     } */
   
@@ -626,7 +677,7 @@ static double min(double a, double b)
 }
 
 /* draw method for ant */
-static Bool draw_ant(antmazestruct *mp,
+static Bool draw_ant(ModeInfo *mi, antmazestruct *mp,
                      const float *Material, int mono, int shadow,
              float ant_step, Bool (*sphere)(float), Bool (*cone)(float)) 
 {
@@ -679,17 +730,21 @@ static Bool draw_ant(antmazestruct *mp,
   glVertex3f(0.00, 0.30, 0.00);
   glColor3fv(MaterialGray);
   glVertex3f(0.40, 0.70, 0.40);
+  mi->polygon_count++;
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, 0.30, 0.00);
   glColor3fv(MaterialGray);
   glVertex3f(0.40, 0.70, -0.40);
+  mi->polygon_count++;
   glEnd();
 
   if(!shadow) {
     glBegin(GL_POINTS);
     glColor3fv(mono ? MaterialGray6 : MaterialRed);
     glVertex3f(0.40, 0.70, 0.40);
+    mi->polygon_count++;
     glVertex3f(0.40, 0.70, -0.40);
+    mi->polygon_count++;
     glEnd();
   }
 
@@ -698,8 +753,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, 0.05, 0.18);
   glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45);
+  mi->polygon_count++;
   glEnd();
 
   /* LEFT-CENTER ARM */
@@ -707,8 +764,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, 0.00, 0.18);
   glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45);
+  mi->polygon_count++;
   glEnd();
 
   /* LEFT-BACK ARM */
@@ -716,8 +775,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, -0.05, 0.18);
   glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45);
+  mi->polygon_count++;
   glEnd();
 
   /* RIGHT-FRONT ARM */
@@ -725,8 +786,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, 0.05, -0.18);
   glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
+  mi->polygon_count++;
   glEnd();
 
   /* RIGHT-CENTER ARM */
@@ -734,8 +797,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, 0.00, -0.18);
   glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
+  mi->polygon_count++;
   glEnd();
 
   /* RIGHT-BACK ARM */
@@ -743,8 +808,10 @@ static Bool draw_ant(antmazestruct *mp,
   glColor3fv(mono ? MaterialGray5 : Material);
   glVertex3f(0.00, -0.05, -0.18);
   glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25);
+  mi->polygon_count++;
   glColor3fv(MaterialGray);
   glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
+  mi->polygon_count++;
   glEnd();
 
   if(!shadow) {
@@ -756,6 +823,7 @@ static Bool draw_ant(antmazestruct *mp,
     glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45);
     glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45);
     glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45);
+    mi->polygon_count += 6;
     glEnd();
   }
 
@@ -790,7 +858,7 @@ static Bool draw_antmaze_strip(ModeInfo * mi)
     glEnable(GL_TEXTURE_2D);
     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);
     glTranslatef(-(BOARDSIZE-1)/2.0, 0.0, -(BOARDSIZE-1)/2.0);
-    draw_board(mp);
+    draw_board(mi, mp);
     glTranslatef(BOARDSIZE/2.0, 0.0, BOARDSIZE/2.0);
     glDisable(GL_TEXTURE_2D);
   }
@@ -823,9 +891,9 @@ static Bool draw_antmaze_strip(ModeInfo * mi)
 
     /* slow down first ant */
     if(i == 0 && mp->part[i] == mp->antpathlength[i])
-      draw_ant(mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
+      draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->first_ant_step, mySphere, myCone);
     else
-      draw_ant(mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
+      draw_ant(mi, mp, MaterialGrayB, mono, 1, mp->ant_step, mySphere, myCone);
 
     glPopMatrix();
 
@@ -851,7 +919,7 @@ static Bool draw_antmaze_strip(ModeInfo * mi)
     if(i == 0 && mp->part[i] == mp->antpathlength[i] && mp->elevator > 0.0) {
       glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
       glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
-      draw_ant(mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
+      draw_ant(mi, mp, antmaterial[i], mono, 1, mp->first_ant_step, mySphere, myCone);
     }
     else {
 /*       glLightfv(GL_LIGHT0, GL_DIFFUSE, df); */
@@ -859,12 +927,12 @@ static Bool draw_antmaze_strip(ModeInfo * mi)
 
       glEnable(GL_TEXTURE_2D);
       glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
-      draw_ant(mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
+      draw_ant(mi, mp, antmaterial[i], mono, 1, mp->ant_step, mySphereTex, myCone);
       glDisable(GL_TEXTURE_2D);
     }
 
 
-/*     draw_ant(antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
+/*     draw_ant(mi, antmaterial[i], mono, 0, ant_step, mySphereTex, myCone); */
 /*     glDisable(GL_TEXTURE_2D); */
     glPopMatrix();
   }
@@ -904,6 +972,7 @@ static Bool draw_antmaze_strip(ModeInfo * mi)
 /*     glVertex3f((sz*i)/BOARDSIZE, (sz*(j+1))/BOARDSIZE, 0.0); */
 /*     glVertex3f((sz*i)/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
 /*     glVertex3f((sz*(i+1))/BOARDSIZE, (sz*j)/BOARDSIZE, 0.0); */
+/*      mi->polygon_count++; */
 /*       } */
 /*   } */
 /*   glEnd(); */
@@ -1100,7 +1169,7 @@ static void update_ants(antmazestruct *mp)
 /*       glPushMatrix(); */
 /*       glTranslatef(-(-(BOARDSIZE-3.5)+(BOARDSIZE-1)/2.0), 0.0,  */
 /*                    -(2.4+BOARDSIZE+(BOARDSIZE-1)/2.0)); */
-/*       draw_board(); */
+/*       draw_board(mi, mp); */
 /*       glPopMatrix(); */
 /*       glDisable(GL_TEXTURE_2D); */
 /*     } */
@@ -1163,8 +1232,6 @@ static void update_ants(antmazestruct *mp)
 static void pinit(antmazestruct *mp) 
 {
   glClearDepth(1.0);
-  glClearColor(0.0, 0.0, 0.0, 1.0);
-  
   glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
   glLightfv(GL_LIGHT0, GL_POSITION, position0);
@@ -1221,15 +1288,6 @@ static void pinit(antmazestruct *mp)
 /*   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); */
 }
 
-ENTRYPOINT void release_antmaze(ModeInfo * mi) 
-{
-  if(antmaze) {
-       free((void *) antmaze);
-       antmaze = (antmazestruct *) NULL;
-  }
-  FreeAllGL(mi);
-}
-
 #define MAX_MAGNIFICATION 10
 #define max(a, b) a < b ? b : a
 #define min(a, b) a < b ? a : b
@@ -1238,55 +1296,30 @@ ENTRYPOINT Bool antmaze_handle_event (ModeInfo *mi, XEvent *event)
 {
   antmazestruct *mp = &antmaze[MI_SCREEN(mi)];
 
-  switch(event->xany.type) {
-  case ButtonPress:
+  if (gltrackball_event_handler (event, mp->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &mp->button_down_p))
+    return True;
 
-    switch(event->xbutton.button) {
+  if (event->xany.type == ButtonPress)
+    {
+      switch(event->xbutton.button) {
 
-    case Button1:
-      mp->button_down_p = True;
-      gltrackball_start(mp->trackball, 
-                       event->xbutton.x, event->xbutton.y,
-                       MI_WIDTH (mi), MI_HEIGHT (mi));
-      break;
-
-    case Button3:
-      mp->focus = (mp->focus + 1) % ANTCOUNT;
-      break;
+      case Button3:
+        mp->focus = (mp->focus + 1) % ANTCOUNT;
+        return True;
       
-    case Button4:
-      mp->mag = max(mp->mag-1, 1);
-      break;
-
-    case Button5:
-      mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
-      break;
-    }
+      case Button4:
+        mp->mag = max(mp->mag-1, 1);
+        return True;
 
-    break;
-    
-  case ButtonRelease:
-
-    switch(event->xbutton.button) {
-    case Button1:
-      mp->button_down_p = False;
-      break;
+      case Button5:
+        mp->mag = min(mp->mag+1, MAX_MAGNIFICATION);
+        return True;
+      }
     }
 
-    break;
-
-  case MotionNotify:
-    if(mp->button_down_p)
-      gltrackball_track(mp->trackball,
-                       event->xmotion.x, event->xmotion.y,
-                       MI_WIDTH (mi), MI_HEIGHT (mi));
-    break;
-    
-  default:
-    return False;
-  }
-
-  return True;
+  return False;
 }
 
 ENTRYPOINT void init_antmaze(ModeInfo * mi) 
@@ -1296,11 +1329,7 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
 
   antmazestruct *mp;
   
-  if (antmaze == NULL) {
-       if ((antmaze = (antmazestruct *) calloc(MI_NUM_SCREENS(mi),
-                                               sizeof (antmazestruct))) == NULL)
-         return;
-  }
+  MI_INIT(mi, antmaze, NULL);
   mp = &antmaze[MI_SCREEN(mi)];
   mp->step = NRAND(90);
   mp->ant_position = NRAND(90);
@@ -1367,7 +1396,7 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
   mp->mag = 4.0;
 
   mp->rot = make_rotator (rot_speed, rot_speed, rot_speed, 1, 0, True);
-  mp->trackball = gltrackball_init ();
+  mp->trackball = gltrackball_init (False);
   
   if ((mp->glx_context = init_GL(mi)) != NULL) {
     reshape_antmaze(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
@@ -1378,6 +1407,22 @@ ENTRYPOINT void init_antmaze(ModeInfo * mi)
     MI_CLEARWINDOW(mi);
 }
 
+static void
+device_rotate(ModeInfo *mi)
+{
+#if 0
+  GLfloat rot = current_device_rotation();
+  glRotatef(rot, 0, 0, 1);
+  if ((rot >  45 && rot <  135) ||
+      (rot < -45 && rot > -135))
+    {
+      GLfloat s = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+      glScalef (1/s, s, 1);
+    }
+#endif
+}
+
+
 ENTRYPOINT void draw_antmaze(ModeInfo * mi) 
 {
   double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
@@ -1396,6 +1441,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   if(!mp->glx_context)
        return;
   
+  mi->polygon_count = 0;
   glXMakeCurrent(display, window, *(mp->glx_context));
 
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -1412,6 +1458,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
+  device_rotate(mi);
 
   glPushMatrix();
 
@@ -1433,7 +1480,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   /* sync */
   if(!draw_antmaze_strip(mi)) {
-    release_antmaze(mi);
+    MI_ABORT(mi);
     return;
   }
 
@@ -1447,6 +1494,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+  device_rotate(mi);
   gluPerspective(45, 1/h, 1, 25.0);
   glMatrixMode(GL_MODELVIEW);
     
@@ -1458,7 +1506,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 
   /* sync */
   if(!draw_antmaze_strip(mi)) {
-    release_antmaze(mi);
+    MI_ABORT(mi);
     return;
   }
 
@@ -1469,6 +1517,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+  device_rotate(mi);
   gluPerspective(45, 1/h, 1, 25.0);
   glMatrixMode(GL_MODELVIEW);
     
@@ -1495,7 +1544,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
   glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
   glBindTexture(GL_TEXTURE_2D, mp->brushedtexture);
-  draw_ant(mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
+  draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2);
   glDisable(GL_TEXTURE_2D);
 
   glPopMatrix();
@@ -1524,6 +1573,7 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 /*   glVertex3f(2.0, 3.0, 0.0); */
 /*   glVertex3f(2.0, -3.0, 0.0); */
 /*   glVertex3f(4.0, -3.0, 0.0); */
+/*   mi->polygon_count++; */
 /*   glEnd(); */
 
 /*   glEnable(GL_LIGHTING); */
@@ -1532,7 +1582,10 @@ ENTRYPOINT void draw_antmaze(ModeInfo * mi)
 /*   glPopMatrix(); */
 /*   glPopMatrix(); */
   
-  if (MI_IS_FPS(mi)) do_fps (mi);
+  if (MI_IS_FPS(mi)) {
+    glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi));
+    do_fps (mi);
+  }
   glFlush();
   
   glXSwapBuffers(display, window);