1 /* glxfonts, Copyright (c) 2001-2014 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * Draws 2D text over the GL scene, e.g., the FPS displays.
13 * The lower-level character rendering code is in texfont.c.
27 /*# include <AGL/agl.h>*/
35 #endif /* HAVE_JWZGLES */
37 #include "resources.h"
43 /* These are in xlock-gl.c */
44 extern void clear_gl_error (void);
45 extern void check_gl_error (const char *type);
48 extern char *progname;
51 #undef DEBUG /* Defining this causes check_gl_error() to be called inside
52 time-critical sections, which could slow things down (since
53 it might result in a round-trip, and stall of the pipeline.)
57 #define countof(x) (sizeof((x))/sizeof((*x)))
60 /* Draws the string on the window at the given pixel position.
61 Newlines and tab stops are honored.
62 Any numbers inside [] will be rendered as a subscript.
63 Assumes the font has been loaded as with load_texture_font().
65 If width and height are 0, then instead the text is placed
66 into the 3D scene at the origin, billboarded to face the
70 print_gl_string (Display *dpy,
71 texture_font_data *data,
72 int window_width, int window_height,
75 Bool clear_background_p)
77 Bool in_scene_p = (window_width == 0);
84 Bool tex_p = glIsEnabled (GL_TEXTURE_2D);
85 Bool texs_p = glIsEnabled (GL_TEXTURE_GEN_S);
86 Bool text_p = glIsEnabled (GL_TEXTURE_GEN_T);
87 Bool light_p = glIsEnabled (GL_LIGHTING);
88 Bool blend_p = glIsEnabled (GL_BLEND);
89 Bool depth_p = glIsEnabled (GL_DEPTH_TEST);
90 Bool cull_p = glIsEnabled (GL_CULL_FACE);
91 Bool fog_p = glIsEnabled (GL_FOG);
97 glGetIntegerv (GL_POLYGON_MODE, opoly);
101 glGetIntegerv (GL_VIEWPORT, ovp);
103 glGetIntegerv (GL_BLEND_DST, &oblend);
104 glGetFloatv (GL_CURRENT_COLOR, color);
106 for (c = string; *c; c++)
107 if (*c == '\n') lines++;
109 texture_string_width (data, "m", &line_height);
113 glEnable (GL_TEXTURE_2D);
115 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
116 glPolygonMode (GL_FRONT, GL_FILL);
118 glDisable (GL_TEXTURE_GEN_S);
119 glDisable (GL_TEXTURE_GEN_T);
120 glDisable (GL_LIGHTING);
121 glDisable (GL_CULL_FACE);
125 glDisable (GL_DEPTH_TEST);
127 /* Each matrix mode has its own stack, so we need to push/pop
130 glMatrixMode(GL_PROJECTION);
134 check_gl_error ("glPushMatrix");
139 glMatrixMode(GL_MODELVIEW);
143 check_gl_error ("glPushMatrix");
148 int rot = (int) current_device_rotation();
149 while (rot <= -180) rot += 360;
150 while (rot > 180) rot -= 360;
153 glViewport (0, 0, window_width, window_height);
154 glOrtho (0, window_width, 0, window_height, -1, 1);
156 if (rot > 135 || rot < -135) /* 180 */
158 glTranslatef (window_width, window_height, 0);
159 glRotatef (180, 0, 0, 1);
161 else if (rot > 45) /* 90 */
163 glTranslatef (window_width, 0, 0);
164 glRotatef (90, 0, 0, 1);
166 else if (rot < -45) /* 270 */
168 glTranslatef(0, window_height, 0);
169 glRotatef (-90, 0, 0, 1);
174 check_gl_error ("glOrtho");
177 /* Let's always dropshadow the FPS and Title text. */
179 clear_background_p = True;
184 glTranslatef (x, y, 0);
187 const XPoint offsets[] = {{ -1, -1 },
195 for (i = 0; i < countof(offsets); i++)
197 if (! clear_background_p)
198 i = countof(offsets)-1;
199 if (offsets[i].x == 0)
203 glTranslatef (offsets[i].x, offsets[i].y, 0);
204 print_texture_string (data, string);
210 check_gl_error ("print_texture_string");
215 glMatrixMode(GL_PROJECTION);
218 if (tex_p) glEnable (GL_TEXTURE_2D); else glDisable (GL_TEXTURE_2D);
219 if (texs_p) glEnable (GL_TEXTURE_GEN_S);/*else glDisable(GL_TEXTURE_GEN_S);*/
220 if (text_p) glEnable (GL_TEXTURE_GEN_T);/*else glDisable(GL_TEXTURE_GEN_T);*/
221 if (blend_p) glEnable (GL_BLEND); else glDisable (GL_BLEND);
222 if (light_p) glEnable (GL_LIGHTING); /*else glDisable (GL_LIGHTING);*/
223 if (depth_p) glEnable (GL_DEPTH_TEST); else glDisable (GL_DEPTH_TEST);
224 if (cull_p) glEnable (GL_CULL_FACE); /*else glDisable (GL_CULL_FACE);*/
225 if (fog_p) glEnable (GL_FOG); /*else glDisable (GL_FOG);*/
228 glViewport (ovp[0], ovp[1], ovp[2], ovp[3]);
230 glBlendFunc (GL_SRC_ALPHA, oblend);
232 # ifndef HAVE_JWZGLES
233 glPolygonMode (GL_FRONT, opoly[0]);
236 glMatrixMode(GL_MODELVIEW);