From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / glsnake.c
index 4d13a93243a70af5d5318c82555cec413eaebbbf..5f20421537ae6d69eca1e3f8691d48e940dcffc8 100644 (file)
 #ifdef HAVE_GLUT
 # include <GL/glut.h>
 #else
-# ifdef HAVE_COCOA
+# ifdef HAVE_JWXYZ
 #  define HAVE_GETTIMEOFDAY
 # else
 #  include <GL/gl.h>
 #  include <GL/glu.h>
 # endif
 #endif
+# ifdef HAVE_ANDROID
+# include <GLES/gl.h>
+#endif
 
 #ifdef HAVE_JWZGLES
 # include "jwzgles.h"
@@ -141,23 +144,23 @@ static GLfloat angvel;
 #define glsnake_init    init_glsnake
 #define glsnake_display draw_glsnake
 #define glsnake_reshape reshape_glsnake
-#define refresh_glsnake 0
+#define free_glsnake 0
 #define release_glsnake 0
-#define glsnake_handle_event 0
+#define glsnake_handle_event xlockmore_no_events
 
 /* xscreensaver defaults */
 #define DEFAULTS "*delay:          30000                      \n" \
                  "*count:          30                         \n" \
                  "*showFPS:        False                      \n" \
-                 "*labelfont:   -*-helvetica-medium-r-normal-*-180-*\n" \
-
+               "*suppressRotationAnimation: True\n" \
+         "*labelfont:   -*-helvetica-medium-r-normal-*-*-180-*-*-*-*-*-*\n" \
 
 
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
 #include "xlockmore.h"
-#include "glxfonts.h"
+#include "texfont.h"
 
 static XrmOptionDescRec opts[] = {
     { "-explode", ".explode", XrmoptionSepArg, DEF_EXPLODE },
@@ -201,12 +204,7 @@ struct model_s {
 struct glsnake_cfg {
 #ifndef HAVE_GLUT
     GLXContext * glx_context;
-# ifdef HAVE_GLBITMAP
-    XFontStruct * font;
-    GLuint font_list;
-# else
-  texture_font_data *font_data;
-# endif
+    texture_font_data *font_data;
 #else
     /* font list number */
     int font;
@@ -1463,13 +1461,7 @@ ModeInfo * mi
     struct glsnake_cfg * bp;
 
     /* set up the conf struct and glx contexts */
-    if (!glc) {
-       glc = (struct glsnake_cfg *) calloc(MI_NUM_SCREENS(mi), sizeof(struct glsnake_cfg));
-       if (!glc) {
-           fprintf(stderr, "%s: out of memory\n", progname);
-           exit(1);
-       }
-    }
+    MI_INIT(mi, glc);
     bp = &glc[MI_SCREEN(mi)];
 
     if ((bp->glx_context = init_GL(mi)) != NULL) {
@@ -1502,11 +1494,7 @@ ModeInfo * mi
     /* set up a font for the labels */
 #ifndef HAVE_GLUT
     if (titles)
-# ifdef HAVE_GLBITMAP
-       load_font(mi->dpy, "labelfont", &bp->font, &bp->font_list);
-# else
-        bp->font_data = load_texture_font (mi->dpy, "labelFont");
-# endif
+        bp->font_data = load_texture_font (mi->dpy, "labelfont");
 #endif
     
     /* build a solid display list */
@@ -1742,15 +1730,9 @@ static void draw_title(
                glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, s[i++]);
        }
 #else
-       print_gl_string(mi->dpy,
-# ifdef HAVE_GLBITMAP
-                        bp->font, bp->font_list,
-# else
-                        bp->font_data,
-# endif
-                       mi->xgwa.width, mi->xgwa.height,
-                       10.0, (float) mi->xgwa.height - 10.0,
-                       s, False);
+       print_texture_label (mi->dpy, bp->font_data,
+                             mi->xgwa.width, mi->xgwa.height,
+                             1, s);
 #endif
     }
     glPopMatrix();
@@ -1786,20 +1768,29 @@ ENTRYPOINT void glsnake_reshape(
 #ifndef HAVE_GLUT
                     ModeInfo * mi,
 #endif
-                    int w, int h
+                    int width, int height
 {
-    glViewport(0, 0, (GLint) w, (GLint) h);
+    double 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, y, width, height);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     /* jwz: 0.05 was too close (left black rectangles) */
-    gluPerspective(zoom, (GLdouble) w / (GLdouble) h, 1.0, 100.0);
+    gluPerspective(zoom, 1/h, 1.0, 100.0);
     gluLookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     glMatrixMode(GL_MODELVIEW);
     /*gluLookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);*/
     glLoadIdentity();
 #ifdef HAVE_GLUT
-    bp->width = w;
-    bp->height = h;
+    bp->width = width;
+    bp->height = height;
 #endif
 }
 
@@ -2279,6 +2270,15 @@ ENTRYPOINT void glsnake_display(
     glRotatef(yspin, 0.0, 1.0, 0.0); 
     glRotatef(zspin, 0.0, 0.0, 1.0); 
 
+# ifdef HAVE_MOBILE    /* Keep it the same relative size when rotated. */
+    {
+      GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+      int o = (int) current_device_rotation();
+      if (o != 0 && o != 180 && o != -180)
+        glScalef (1/h, 1/h, 1/h);
+    }
+# endif
+
     /* now draw each node along the snake -- this is quite ugly :p */
     mi->polygon_count = 0;
     for (i = 0; i < NODE_COUNT; i++) {