+/* report a GL error. */
+void
+check_gl_error (const char *type)
+{
+ char buf[100];
+ GLenum i;
+ const char *e;
+ switch ((i = glGetError())) {
+ case GL_NO_ERROR: return;
+ case GL_INVALID_ENUM: e = "invalid enum"; break;
+ case GL_INVALID_VALUE: e = "invalid value"; break;
+ case GL_INVALID_OPERATION: e = "invalid operation"; break;
+ case GL_STACK_OVERFLOW: e = "stack overflow"; break;
+ case GL_STACK_UNDERFLOW: e = "stack underflow"; break;
+ case GL_OUT_OF_MEMORY: e = "out of memory"; break;
+#ifdef GL_TABLE_TOO_LARGE_EXT
+ case GL_TABLE_TOO_LARGE_EXT: e = "table too large"; break;
+#endif
+#ifdef GL_TEXTURE_TOO_LARGE_EXT
+ case GL_TEXTURE_TOO_LARGE_EXT: e = "texture too large"; break;
+#endif
+ default:
+ e = buf; sprintf (buf, "unknown error %d", (int) i); break;
+ }
+ fprintf (stderr, "%s: %s error: %s\n", progname, type, e);
+ exit (1);
+}
+
+
+\f
+
+/* Frames-per-second statistics */
+
+static int fps_text_x = 10;
+static int fps_text_y = 10;
+static int fps_sample_frames = 10;
+static GLuint font_dlist;
+
+static void
+fps_init (ModeInfo *mi)
+{
+ const char *font = get_string_resource ("fpsFont", "Font");
+ XFontStruct *f;
+ Font id;
+ int first, last;
+
+ if (!font) font = "-*-courier-bold-r-normal-*-180-*";
+ 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 ();
+ font_dlist = glGenLists ((GLuint) last+1);
+ check_gl_error ("glGenLists");
+
+ if (get_boolean_resource ("fpsTop", "FPSTop"))
+ fps_text_y = - (f->ascent + 10);
+
+ glXUseXFont(id, first, last-first+1, font_dlist + first);
+ check_gl_error ("glXUseXFont");
+}
+
+
+static void
+fps_print_string (ModeInfo *mi, GLfloat x, GLfloat y, const char *string)
+{
+ int i;
+ /* save the current state */
+ /* note: could be expensive! */
+
+ if (y < 0)
+ y = mi->xgwa.height + y;
+
+ clear_gl_error ();
+ glPushAttrib(GL_ALL_ATTRIB_BITS);