From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / glmatrix.c
index a5003185981dd0958720a37cab705621803e1741..7683c39ffe614331adce6e5f4922259a18fc418a 100644 (file)
@@ -20,7 +20,7 @@
                        "*showFPS:      False         \n" \
                        "*wireframe:    False         \n" \
 
                        "*showFPS:      False         \n" \
                        "*wireframe:    False         \n" \
 
-# define refresh_matrix 0
+# define free_matrix 0
 # define release_matrix 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 # define release_matrix 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
@@ -572,8 +572,15 @@ ENTRYPOINT void
 reshape_matrix (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
 reshape_matrix (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
+  int y = 0;
 
 
-  glViewport (0, 0, (GLint) width, (GLint) height);
+  if (width > height * 5) {   /* tiny window: show middle */
+    height = width * 9/16;
+    y = -height/2;
+    h = height / (GLfloat) width;
+  }
+
+  glViewport (0, y, (GLint) width, (GLint) height);
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
@@ -632,6 +639,10 @@ bigendian (void)
 
    If this hack ever grows into something that displays full Latin1 text,
    well then, Something Else Will Need To Be Done.
 
    If this hack ever grows into something that displays full Latin1 text,
    well then, Something Else Will Need To Be Done.
+
+   Since currently GLMatrix does not run textclient / xscreensaver-text,
+   it's not an issue.  (XMatrix does that.)
+
  */
 static void
 spank_image (matrix_configuration *mp, XImage *xi)
  */
 static void
 spank_image (matrix_configuration *mp, XImage *xi)
@@ -778,7 +789,8 @@ load_textures (ModeInfo *mi, Bool flip_p)
   glGenTextures (1, &mp->texture);
 
   glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
   glGenTextures (1, &mp->texture);
 
   glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
-  glPixelStorei (GL_UNPACK_ROW_LENGTH, xi->width);
+  /* messes up -fps */
+  /* glPixelStorei (GL_UNPACK_ROW_LENGTH, xi->width);*/
   glBindTexture (GL_TEXTURE_2D, mp->texture);
   check_gl_error ("texture init");
   glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, xi->width, xi->height, 0, GL_RGBA,
   glBindTexture (GL_TEXTURE_2D, mp->texture);
   check_gl_error ("texture init");
   glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, xi->width, xi->height, 0, GL_RGBA,
@@ -817,14 +829,7 @@ init_matrix (ModeInfo *mi)
   if (wire)
     do_texture = False;
 
   if (wire)
     do_texture = False;
 
-  if (!mps) {
-    mps = (matrix_configuration *)
-      calloc (MI_NUM_SCREENS(mi), sizeof (matrix_configuration));
-    if (!mps) {
-      fprintf(stderr, "%s: out of memory\n", progname);
-      exit(1);
-    }
-  }
+  MI_INIT (mi, mps);
 
   mp = &mps[MI_SCREEN(mi)];
   mp->glx_context = init_GL(mi);
 
   mp = &mps[MI_SCREEN(mi)];
   mp->glx_context = init_GL(mi);
@@ -879,18 +884,7 @@ init_matrix (ModeInfo *mi)
   glEnable(GL_NORMALIZE);
 
   if (do_texture)
   glEnable(GL_NORMALIZE);
 
   if (do_texture)
-    {
-      load_textures (mi, flip_p);
-      glEnable(GL_TEXTURE_2D);
-      glEnable(GL_BLEND);
-
-      /* Jeff Epler points out:
-         By using GL_ONE instead of GL_SRC_ONE_MINUS_ALPHA, glyphs are
-         added to each other, so that a bright glyph with a darker one
-         in front is a little brighter than the bright glyph alone.
-       */
-      glBlendFunc (GL_SRC_ALPHA, GL_ONE);
-    }
+    load_textures (mi, flip_p);
 
   /* to scale coverage-percent to strips, this number looks about right... */
   mp->nstrips = (int) (density * 2.2);
 
   /* to scale coverage-percent to strips, this number looks about right... */
   mp->nstrips = (int) (density * 2.2);
@@ -1002,6 +996,20 @@ draw_matrix (ModeInfo *mi)
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
   glPushMatrix ();
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
   glPushMatrix ();
+  glRotatef(current_device_rotation(), 0, 0, 1);
+
+  if (do_texture)
+    {
+      glEnable(GL_TEXTURE_2D);
+      glEnable(GL_BLEND);
+
+      /* Jeff Epler points out:
+         By using GL_ONE instead of GL_SRC_ONE_MINUS_ALPHA, glyphs are
+         added to each other, so that a bright glyph with a darker one
+         in front is a little brighter than the bright glyph alone.
+       */
+      glBlendFunc (GL_SRC_ALPHA, GL_ONE);
+    }
 
   if (do_rotate)
     {
 
   if (do_rotate)
     {