1 #ifdef _WIN32
2 #include "windows.h"
3 #endif
4 #include "GL/gl.h"
5 
6 #include "stdio.h"
7 #include "stdarg.h"
8 #include "string.h"
9 #include "GL/gl.h"
10 #include "GL/glut.h"
11 
glprintf(const char * fmt,...)12 void glprintf(const char *fmt, ...)
13 {
14 	float		length=0;								// Used To Find The Length Of The Text
15 	char		text[256];								// Holds Our String
16 	va_list		ap;										// Pointer To List Of Arguments
17 	int i,tl;
18 
19 	if (fmt==0) return;
20 
21 	va_start(ap, fmt);									// Parses The String For Variables
22 	vsprintf(text, fmt, ap);							// And Converts Symbols To Actual Numbers
23 	va_end(ap);											// Results Are Stored In Text
24 
25 	tl=strlen(text);
26 	for(i=0;i<tl;i++) {
27 		length+=glutStrokeWidth(GLUT_STROKE_MONO_ROMAN,text[i]);
28 	} /* for /*/
29 
30 	glTranslatef(-length/2,0.0f,0.0f);					// Center Our Text On The Screen
31 
32 	glNormal3f(0.0,0.0,1.0);
33 	for(i=0;i<tl;i++) {
34 		glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,text[i]);
35 	} /* for */
36 } /* glprintf */
37 
38 
39 
scaledglprintf(float sx,float sy,const char * fmt,...)40 void scaledglprintf(float sx,float sy,const char *fmt, ...)
41 {
42 	float		length=0;								// Used To Find The Length Of The Text
43 	char		text[256];								// Holds Our String
44 	va_list		ap;										// Pointer To List Of Arguments
45 	int i,tl;
46 
47 	if (fmt==0) return;
48 
49 	va_start(ap, fmt);									// Parses The String For Variables
50 	vsprintf(text, fmt, ap);							// And Converts Symbols To Actual Numbers
51 	va_end(ap);											// Results Are Stored In Text
52 
53 	tl=strlen(text);
54 	for(i=0;i<tl;i++) {
55 		length+=glutStrokeWidth(GLUT_STROKE_MONO_ROMAN,text[i]);
56 	} /* for /*/
57 
58 	glMatrixMode(GL_MODELVIEW);
59 	glPushMatrix();
60 	glScalef(sx,sy,1.0f);
61 
62 	glTranslatef(-length/2,0.0f,0.0f);					// Center Our Text On The Screen
63 
64 	glNormal3f(0.0,0.0,1.0);
65 	for(i=0;i<tl;i++) {
66 		glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,text[i]);
67 	} /* for */
68 
69 	glPopMatrix();
70 } /* scaledglprintf */
71 
72 
73 
scaledglprintf2(float sx,float sy,const char * fmt,...)74 void scaledglprintf2(float sx,float sy,const char *fmt, ...)
75 {
76 	float		length=0;								// Used To Find The Length Of The Text
77 	char		text[256];								// Holds Our String
78 	va_list		ap;										// Pointer To List Of Arguments
79 	int i,tl;
80 
81 	if (fmt==0) return;
82 
83 	va_start(ap, fmt);									// Parses The String For Variables
84 	vsprintf(text, fmt, ap);							// And Converts Symbols To Actual Numbers
85 	va_end(ap);											// Results Are Stored In Text
86 
87 	tl=strlen(text);
88 	for(i=0;i<tl;i++) {
89 		length+=glutStrokeWidth(GLUT_STROKE_MONO_ROMAN,text[i]);
90 	} /* for /*/
91 
92 	glMatrixMode(GL_MODELVIEW);
93 	glPushMatrix();
94 	glScalef(sx,sy,1.0f);
95 
96 	glNormal3f(0.0,0.0,1.0);
97 	for(i=0;i<tl;i++) {
98 		glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,text[i]);
99 	} /* for */
100 
101 	glPopMatrix();
102 } /* scaledglprintf2 */
103 
104 
105 
fittedglprintf(float sx,float sy,const char * fmt,...)106 void fittedglprintf(float sx,float sy,const char *fmt, ...)
107 {
108 	float		length=0;								// Used To Find The Length Of The Text
109 	char		text[256];								// Holds Our String
110 	va_list		ap;										// Pointer To List Of Arguments
111 	int i,tl;
112 
113 	if (fmt==0) return;
114 
115 	va_start(ap, fmt);									// Parses The String For Variables
116 	vsprintf(text, fmt, ap);							// And Converts Symbols To Actual Numbers
117 	va_end(ap);											// Results Are Stored In Text
118 
119 	tl=strlen(text);
120 	for(i=0;i<tl;i++) {
121 		length+=glutStrokeWidth(GLUT_STROKE_MONO_ROMAN,text[i]);
122 	} /* for /*/
123 
124 	glMatrixMode(GL_MODELVIEW);
125 	glPushMatrix();
126 	glScalef(sx/length,sy/(119.05f+33.33f),1.0f);
127 
128 	glTranslatef(-length/2,0.0f,0.0f);					// Center Our Text On The Screen
129 
130 	glNormal3f(0.0,0.0,1.0);
131 	for(i=0;i<tl;i++) {
132 		glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,text[i]);
133 	} /* for */
134 
135 	glPopMatrix();
136 } /* fittedglprintf */
137