From http://www.jwz.org/xscreensaver/xscreensaver-5.39.tar.gz
[xscreensaver] / hacks / glx / starwars.c
index f4a5850380eddb9bc71341f746efa41578e5fd37..1efcd154c321d84ffd6e9e4c38790cccab820089 100644 (file)
@@ -1,4 +1,4 @@
-/* starwars, Copyright (c) 1998-2015 Jamie Zawinski <jwz@jwz.org> and
+/* starwars, Copyright (c) 1998-2018 Jamie Zawinski <jwz@jwz.org> and
  * Claudio Matsuoka <claudio@helllabs.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -46,8 +46,8 @@
                 "*textLiteral: " DEF_TEXT "\n" \
                 "*program: xscreensaver-text --cols 0"  /* don't wrap */
 
-# define refresh_sws 0
-# define sws_handle_event 0
+# define release_sws 0
+# define sws_handle_event xlockmore_no_events
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -86,7 +86,7 @@
 #define MAX_THICK_LINES   25
 #define FONT_WEIGHT       14
 
-#ifndef USE_IPHONE
+#ifndef HAVE_MOBILE
 # define KEEP_ASPECT   /* Letterboxing looks dumb on iPhone. */
 #endif
 
@@ -283,7 +283,6 @@ get_more_lines (sws_configuration *sc)
 {
   /* wrap anyway, if it's absurdly long. */
   int wrap_pix = (wrap_p ? sc->line_pixel_width : 10000);
-  int col_pix = 0;
 
   char *s = sc->buf;
 
@@ -410,7 +409,6 @@ get_more_lines (sws_configuration *sc)
 
               sc->buf[sc->buf_tail] = 0;
               s = sc->buf;
-              col_pix = 0;
 
               break;
             }
@@ -570,6 +568,12 @@ init_stars (ModeInfo *mi, int width, int height)
   int max_size = 3;
   GLfloat inc = 0.5;
   int steps = max_size / inc;
+  GLfloat scale = 1;
+
+  if (MI_WIDTH(mi) > 2560) {  /* Retina displays */
+    scale *= 2;
+    nstars = (size/scale) * (size/scale) / 320;
+  }
 
   glDeleteLists (sc->star_list, 1);
   sc->star_list = glGenLists (1);
@@ -579,7 +583,7 @@ init_stars (ModeInfo *mi, int width, int height)
 
   for (j = 1; j <= steps; j++)
     {
-      glPointSize(inc * j);
+      glPointSize(inc * j * scale);
       glBegin (GL_POINTS);
       for (i = 0; i < nstars / steps; i++)
         {
@@ -620,9 +624,11 @@ reshape_sws (ModeInfo *mi, int width, int height)
     }
 #endif
 
-    glMatrixMode (GL_PROJECTION);
     glViewport (0, yoff, w, h);
 
+    glMatrixMode (GL_PROJECTION);
+    glLoadIdentity();
+
     glMatrixMode (GL_MODELVIEW);
     glLoadIdentity ();
     gluPerspective (80.0, 1/desired_aspect, 1000, 55000);
@@ -630,8 +636,6 @@ reshape_sws (ModeInfo *mi, int width, int height)
                0.0, 0.0, 0.0,
                0.0, 1.0, 0.0);
 
-    glRotatef(rot, 0, 0, 1);
-
     /* Horrible kludge to prevent the text from materializing already
        on screen on iPhone in landscape mode.
      */
@@ -725,14 +729,7 @@ init_sws (ModeInfo *mi)
 
   sws_configuration *sc = 0;
 
-  if (!scs) {
-    scs = (sws_configuration *)
-      calloc (MI_NUM_SCREENS(mi), sizeof (sws_configuration));
-    if (!scs) {
-      fprintf(stderr, "%s: out of memory\n", progname);
-      exit(1);
-    }
-  }
+  MI_INIT (mi, scs);
 
   sc = &scs[MI_SCREEN(mi)];
 
@@ -877,9 +874,6 @@ draw_stars (ModeInfo *mi)
       glRotatef (sc->star_theta, 0.0, 0.0, 1.0);
       if (textures_p) glDisable (GL_TEXTURE_2D);
 
-      /* Keep the stars pointing in the same direction after rotation */
-      glRotatef(current_device_rotation(), 0, 0, 1);
-
       glCallList (sc->star_list);
       if (textures_p) glEnable (GL_TEXTURE_2D);
     }
@@ -911,7 +905,7 @@ draw_sws (ModeInfo *mi)
   glMatrixMode (GL_MODELVIEW);
   glPushMatrix ();
 
-# ifdef USE_IPHONE
+# ifdef HAVE_MOBILE
   /* Need to do this every time to get device rotation right */
   reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
 # endif
@@ -1060,21 +1054,13 @@ draw_sws (ModeInfo *mi)
 }
 
 ENTRYPOINT void
-release_sws (ModeInfo *mi)
+free_sws (ModeInfo *mi)
 {
-  if (scs) {
-    int screen;
-    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-      sws_configuration *sc = &scs[screen];
-      if (sc->tc)
-        textclient_close (sc->tc);
-
-      /* #### there's more to free here */
-    }
-    free (scs);
-    scs = 0;
-  }
-  FreeAllGL(mi);
+  sws_configuration *sc = &scs[MI_SCREEN(mi)];
+  if (sc->tc)
+    textclient_close (sc->tc);
+
+  /* #### there's more to free here */
 }