http://www.tienza.es/crux/src/www.jwz.org/xscreensaver/xscreensaver-5.05.tar.gz
[xscreensaver] / hacks / glx / glxfonts.c
index 3443e4f45e10406b34e9844b3515023bff93475a..37076724f2f6bc0b226d99c1384962a653ba9b4a 100644 (file)
@@ -1,4 +1,4 @@
-/* glxfonts, Copyright (c) 2001-2004 Jamie Zawinski <jwz@jwz.org>
+/* glxfonts, Copyright (c) 2001-2008 Jamie Zawinski <jwz@jwz.org>
  * Loads X11 fonts for use with OpenGL.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * implied warranty.
  */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
-#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <GL/glx.h>
-#include <GL/glu.h>
+
+#ifdef HAVE_COCOA
+# include "jwxyz.h"
+# include <OpenGL/gl.h>
+# include <OpenGL/glu.h>
+# include <AGL/agl.h>
+#else
+# include <GL/glx.h>
+# include <GL/glu.h>
+#endif
+
 #include "resources.h"
 #include "glxfonts.h"
 
@@ -36,10 +47,11 @@ extern char *progname;
 void
 load_font (Display *dpy, char *res, XFontStruct **font_ret, GLuint *dlist_ret)
 {
-  const char *font = get_string_resource (res, "Font");
+  XFontStruct *f;
+
+  const char *font = get_string_resource (dpy, res, "Font");
   const char *def1 = "-*-times-bold-r-normal-*-180-*";
   const char *def2 = "fixed";
-  XFontStruct *f;
   Font id;
   int first, last;
 
@@ -76,6 +88,9 @@ load_font (Display *dpy, char *res, XFontStruct **font_ret, GLuint *dlist_ret)
   first = f->min_char_or_byte2;
   last = f->max_char_or_byte2;
   
+
+# ifndef HAVE_COCOA /* Xlib version */
+
   if (dlist_ret)
     {
       clear_gl_error ();
@@ -85,6 +100,29 @@ load_font (Display *dpy, char *res, XFontStruct **font_ret, GLuint *dlist_ret)
       check_gl_error ("glXUseXFont");
     }
 
+# else  /* HAVE_COCOA */
+
+  {
+    int afid, face, size;
+    afid = jwxyz_font_info (id, &size, &face);
+
+    if (dlist_ret)
+      {
+        clear_gl_error ();
+        *dlist_ret = glGenLists ((GLuint) last+1);
+        check_gl_error ("glGenLists");
+
+        AGLContext ctx = aglGetCurrentContext();
+        if (! aglUseFont (ctx, afid, face, size, 
+                          first, last-first+1, *dlist_ret + first)) {
+          check_gl_error ("aglUseFont");
+          abort();
+      }
+    }
+  }
+
+# endif  /* HAVE_COCOA */
+
   if (font_ret)
     *font_ret = f;
 }
@@ -152,7 +190,7 @@ print_gl_string (Display *dpy,
         glRasterPos2f (x, y);
         for (i = 0; i < strlen(string); i++)
           {
-            char c = string[i];
+            unsigned char c = (unsigned char) string[i];
             if (c == '\n')
               {
                 glRasterPos2f (x, (y -= line_height));