http://ftp.ksu.edu.tw/FTP/FreeBSD/distfiles/xscreensaver-4.20.tar.gz
[xscreensaver] / hacks / glx / glsnake.c
index dd533539f41e0b06c4142465aa6badb9025dd794..07f9c54d90f0925b2272180dc0d1a20c5ed8d511 100644 (file)
@@ -36,7 +36,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <libgen.h>
 
 /* angles */
 #define ZERO     0.0
@@ -157,6 +156,7 @@ extern XtAppContext app;
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
 #include "xlockmore.h"
+#include "glxfonts.h"
 
 static XrmOptionDescRec opts[] = {
     { "-explode", ".explode", XrmoptionSepArg, DEF_EXPLODE },
@@ -165,27 +165,27 @@ static XrmOptionDescRec opts[] = {
     { "-statictime", ".statictime", XrmoptionSepArg, DEF_STATICTIME },
     { "-yangvel", ".yangvel", XrmoptionSepArg, DEF_YANGVEL },
     { "-zangvel", ".zangvel", XrmoptionSepArg, DEF_ZANGVEL },
-    { "-altcolour", ".altcolour", XrmoptionNoArg, (caddr_t) "True" },
-    { "-no-altcolour", ".altcolour", XrmoptionNoArg, (caddr_t) "False" },
-    { "-titles", ".titles", XrmoptionNoArg, (caddr_t) "True" },
-    { "-no-titles", ".titles", XrmoptionNoArg, (caddr_t) "False" },
+    { "-altcolour", ".altcolour", XrmoptionNoArg, "True" },
+    { "-no-altcolour", ".altcolour", XrmoptionNoArg, "False" },
+    { "-titles", ".titles", XrmoptionNoArg, "True" },
+    { "-no-titles", ".titles", XrmoptionNoArg, "False" },
     { "-zoom", ".zoom", XrmoptionSepArg, DEF_ZOOM },
-    { "-wireframe", ".wireframe", XrmoptionNoArg, (caddr_t) "true" },
-    { "-no-wireframe", ".wireframe", XrmoptionNoArg, (caddr_t) "false" },
+    { "-wireframe", ".wireframe", XrmoptionNoArg, "true" },
+    { "-no-wireframe", ".wireframe", XrmoptionNoArg, "false" },
 };
 
 static argtype vars[] = {
-    {(caddr_t *) &explode, "explode", "Explode", DEF_EXPLODE, t_Float},
-    {(caddr_t *) &angvel, "angvel", "Angular Velocity", DEF_ANGVEL, t_Float},
-    {(caddr_t *) &accel, "accel", "Acceleration", DEF_ACCEL, t_Float},
-    {(caddr_t *) &statictime, "statictime", "Static Time", DEF_STATICTIME, t_Int},
-    {(caddr_t *) &yangvel, "yangvel", "Angular Velocity about Y axis", DEF_YANGVEL, t_Float},
-    {(caddr_t *) &zangvel, "zangvel", "Angular Velocity about X axis", DEF_ZANGVEL, t_Float},
-    {(caddr_t *) &interactive, "interactive", "Interactive", DEF_INTERACTIVE, t_Bool},
-    {(caddr_t *) &altcolour, "altcolour", "Alternate Colour Scheme", DEF_ALTCOLOUR, t_Bool},
-    {(caddr_t *) &titles, "titles", "Titles", DEF_TITLES, t_Bool},
-    {(caddr_t *) &zoom, "zoom", "Zoom", DEF_ZOOM, t_Float},
-    {(caddr_t *) &wireframe, "wireframe", "Wireframe", DEF_WIREFRAME, t_Bool},
+    {&explode, "explode", "Explode", DEF_EXPLODE, t_Float},
+    {&angvel, "angvel", "Angular Velocity", DEF_ANGVEL, t_Float},
+    {&accel, "accel", "Acceleration", DEF_ACCEL, t_Float},
+    {&statictime, "statictime", "Static Time", DEF_STATICTIME, t_Int},
+    {&yangvel, "yangvel", "Angular Velocity about Y axis", DEF_YANGVEL, t_Float},
+    {&zangvel, "zangvel", "Angular Velocity about X axis", DEF_ZANGVEL, t_Float},
+    {&interactive, "interactive", "Interactive", DEF_INTERACTIVE, t_Bool},
+    {&altcolour, "altcolour", "Alternate Colour Scheme", DEF_ALTCOLOUR, t_Bool},
+    {&titles, "titles", "Titles", DEF_TITLES, t_Bool},
+    {&zoom, "zoom", "Zoom", DEF_ZOOM, t_Float},
+    {&wireframe, "wireframe", "Wireframe", DEF_WIREFRAME, t_Bool},
 };
 
 ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
@@ -1401,33 +1401,6 @@ void gettime(snaketime *t)
 #endif /* !HAVE_GETTIMEOFDAY */
 }
 
-#ifndef HAVE_GLUT
-static void load_font(ModeInfo * mi, char * res, XFontStruct ** fontp, GLuint * dlistp) {
-    const char * font = get_string_resource(res, "Font");
-    XFontStruct * f;
-    Font id;
-    int first, last;
-
-    if (!font)
-       font = "-*-helvetica-medium-r-*-*-*-120-*";
-
-    f = XLoadQueryFont(mi->dpy, font);
-    if (!f)
-       f = XLoadQueryFont(mi->dpy, "fixed");
-
-    id = f->fid;
-    first = f->min_char_or_byte2;
-    last = f->max_char_or_byte2;
-
-    clear_gl_error();
-    *dlistp = glGenLists((GLuint) last + 1);
-    check_gl_error("glGenLists");
-    glXUseXFont(id, first, last - first + 1, *dlistp + first);
-    check_gl_error("glXUseXFont");
-
-    *fontp = f;
-}
-#endif
 
 void start_morph(int model_index, int immediate);
 
@@ -1480,7 +1453,7 @@ ModeInfo * mi
     /* set up a font for the labels */
 #ifndef HAVE_GLUT
     if (titles)
-       load_font(mi, "labelfont", &bp->font, &bp->font_list);
+       load_font(mi->dpy, "labelfont", &bp->font, &bp->font_list);
 #endif
     
     /* build a solid display list */
@@ -1664,25 +1637,15 @@ void draw_title(
     {
        char interactstr[] = "interactive";
        char * s;
-       int i = 0;
-#ifdef HAVE_GLUT
-       int w;
-#endif
-       
        if (interactive)
            s = interactstr;
        else
            s = model[glc->next_model].name;
-#ifdef HAVE_GLUT
-       w = glutBitmapLength(GLUT_BITMAP_HELVETICA_12, (unsigned char *) s);
-       glRasterPos2f(glc->width - w - 3, 4);
-       while (s[i] != '\0')
-           glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, s[i++]);
-#else
-       glRasterPos2f(10, mi->xgwa.height - 10 - (bp->font->ascent + bp->font->descent));
-       while (s[i] != '\0')
-           glCallList(bp->font_list + (int)s[i++]);
-#endif
+
+        print_gl_string (mi->dpy, bp->font, bp->font_list,
+                         mi->xgwa.width, mi->xgwa.height,
+                         10, mi->xgwa.height - 10,
+                         s);
     }
     glPopMatrix();
     glMatrixMode(GL_PROJECTION);
@@ -1849,6 +1812,11 @@ float morph_percent(void) {
        /* ang_diff / rot approaches 0, we want the complement */
        retval = 1.0 - (ang_diff_max / rot_max);
        /* protect against naan */
+
+/* Apparently some systems (Solaris) don't have isinf() */
+#undef isinf
+#define isinf(x) (((x) > 999999999999.9) || ((x) < -999999999999.9))
+
        if (isnan(retval) || isinf(retval)) retval = 1.0;
     }
     /*printf("morph_pct = %f\n", retval);*/