1 /* fps, Copyright (c) 2001-2008 Jamie Zawinski <jwz@jwz.org>
2 * Draw a frames-per-second display (Xlib and OpenGL).
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
15 #endif /* HAVE_CONFIG_H */
19 # include <OpenGL/gl.h>
20 # include <OpenGL/glu.h>
22 #else /* !HAVE_COCOA -- real Xlib */
25 #endif /* !HAVE_COCOA */
27 #include "xlockmoreI.h"
31 /* These are in xlock-gl.c */
32 extern void clear_gl_error (void);
33 extern void check_gl_error (const char *type);
37 xlockmore_gl_fps_init (fps_state *st)
39 XFontStruct *f = st->font;
40 int first = f->min_char_or_byte2;
41 int last = f->max_char_or_byte2;
44 st->font_dlist = glGenLists ((GLuint) last+1);
45 check_gl_error ("glGenLists");
49 glXUseXFont (f->fid, first, last-first+1, st->font_dlist + first);
50 check_gl_error ("glXUseXFont");
52 # else /* HAVE_COCOA */
54 AGLContext ctx = aglGetCurrentContext();
56 afid = jwxyz_font_info (f->fid, &size, &face);
58 if (! aglUseFont (ctx, afid, face, size,
59 first, last-first+1, st->font_dlist + first)) {
60 check_gl_error ("aglUseFont");
64 # endif /* HAVE_COCOA */
69 /* Callback in xscreensaver_function_table, via xlockmore.c.
72 xlockmore_gl_compute_fps (Display *dpy, Window w, fps_state *fpst,
75 ModeInfo *mi = (ModeInfo *) closure;
79 xlockmore_gl_fps_init (fpst);
82 fps_compute (fpst, mi->polygon_count);
86 /* Called directly from GL programs (as `do_fps') before swapping buffers.
89 xlockmore_gl_draw_fps (ModeInfo *mi)
91 fps_state *st = mi->fpst;
92 if (st) /* might be too early */
94 XWindowAttributes xgwa;
97 int lh = st->font->ascent + st->font->descent;
100 XGetWindowAttributes (st->dpy, st->window, &xgwa);
101 for (s = st->string; *s; s++)
102 if (*s == '\n') lines++;
105 y = xgwa.height + y - lines*lh;
106 y += lines*lh + st->font->descent;
109 print_gl_string (st->dpy, st->font, st->font_dlist,
110 xgwa.width, xgwa.height,
111 st->x, y, st->string, st->clear_p);