1 /*
2  * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that (i) the above copyright notices and this permission notice appear in
7  * all copies of the software and related documentation, and (ii) the name of
8  * Silicon Graphics may not be used in any advertising or
9  * publicity relating to the software without the specific, prior written
10  * permission of Silicon Graphics.
11  *
12  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13  * ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include "glut_wrap.h"
29 
30 
31 #define OPENGL_WIDTH 24
32 #define OPENGL_HEIGHT 13
33 
34 
35 char string[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz";
36 GLenum rgb, doubleBuffer, windType;
37 float angleX = 0.0, angleY = 0.0, angleZ = 0.0;
38 float scaleX = 1.0, scaleY = 1.0, scaleZ = 1.0;
39 float shiftX = 0.0, shiftY = 0.0, shiftZ = 0.0;
40 
41 
42 #include "tkmap.c"
43 
44 
DrawBitmapString(void * font,const char * string)45 static void DrawBitmapString(void *font, const char *string)
46 {
47     int i;
48 
49     for (i = 0; string[i]; i++)
50 	glutBitmapCharacter(font, string[i]);
51 }
52 
DrawStrokeString(void * font,const char * string)53 static void DrawStrokeString(void *font, const char *string)
54 {
55     int i;
56 
57     for (i = 0; string[i]; i++)
58 	glutStrokeCharacter(font, string[i]);
59 }
60 
Init(void)61 static void Init(void)
62 {
63 
64     glClearColor(0.0, 0.0, 0.0, 0.0);
65     glClearIndex(0.0);
66 }
67 
Reshape(int width,int height)68 static void Reshape(int width, int height)
69 {
70 
71     glViewport(0, 0, (GLint)width, (GLint)height);
72 
73     glMatrixMode(GL_PROJECTION);
74     glLoadIdentity();
75     glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0);
76     glMatrixMode(GL_MODELVIEW);
77 }
78 
Key2(int key,int x,int y)79 static void Key2(int key, int x, int y)
80 {
81 
82     switch (key) {
83       case GLUT_KEY_LEFT:
84 	shiftX -= 20.0;
85 	break;
86       case GLUT_KEY_RIGHT:
87 	shiftX += 20.0;
88 	break;
89       case GLUT_KEY_UP:
90 	shiftY += 20.0;
91 	break;
92       case GLUT_KEY_DOWN:
93 	shiftY -= 20.0;
94 	break;
95       default:
96 	return;
97     }
98 
99     glutPostRedisplay();
100 }
101 
Key(unsigned char key,int x,int y)102 static void Key(unsigned char key, int x, int y)
103 {
104 
105     switch (key) {
106       case 27:
107         exit(1);
108 
109       case 'n':
110 	shiftZ += 20.0;
111 	break;
112       case 'm':
113 	shiftZ -= 20.0;
114 	break;
115 
116       case 'q':
117 	scaleX -= 0.1;
118 	if (scaleX < 0.1) {
119 	    scaleX = 0.1;
120 	}
121 	break;
122       case 'w':
123 	scaleX += 0.1;
124 	break;
125       case 'a':
126 	scaleY -= 0.1;
127 	if (scaleY < 0.1) {
128 	    scaleY = 0.1;
129 	}
130 	break;
131       case 's':
132 	scaleY += 0.1;
133 	break;
134       case 'z':
135 	scaleZ -= 0.1;
136 	if (scaleZ < 0.1) {
137 	    scaleZ = 0.1;
138 	}
139 	break;
140       case 'x':
141 	scaleZ += 0.1;
142 	break;
143 
144       case 'e':
145 	angleX -= 5.0;
146 	if (angleX < 0.0) {
147 	    angleX = 360.0 + angleX;
148 	}
149 	break;
150       case 'r':
151 	angleX += 5.0;
152 	if (angleX > 360.0) {
153 	    angleX = angleX - 360.0;
154 	}
155 	break;
156       case 'd':
157 	angleY -= 5.0;
158 	if (angleY < 0.0) {
159 	    angleY = 360.0 + angleY;
160 	}
161 	break;
162       case 'f':
163 	angleY += 5.0;
164 	if (angleY > 360.0) {
165 	    angleY = angleY - 360.0;
166 	}
167 	break;
168       case 'c':
169 	angleZ -= 5.0;
170 	if (angleZ < 0.0) {
171 	    angleZ = 360.0 + angleZ;
172 	}
173 	break;
174       case 'v':
175 	angleZ += 5.0;
176 	if (angleZ > 360.0) {
177 	    angleZ = angleZ - 360.0;
178 	}
179 	break;
180       default:
181 	return;
182     }
183 
184     glutPostRedisplay();
185 }
186 
Draw(void)187 static void Draw(void)
188 {
189 
190     glClear(GL_COLOR_BUFFER_BIT);
191 
192     SetColor(COLOR_WHITE);
193 
194     glPushMatrix();
195 
196     glTranslatef(shiftX, shiftY, shiftZ);
197     glRotatef(angleX, 1.0, 0.0, 0.0);
198     glRotatef(angleY, 0.0, 1.0, 0.0);
199     glRotatef(angleZ, 0.0, 0.0, 1.0);
200     glScalef(scaleX, scaleY, scaleZ);
201 
202     glPushMatrix();
203     glRasterPos2f(-390.5, 0.5);
204     DrawBitmapString(GLUT_BITMAP_9_BY_15, string);
205     glPopMatrix();
206 
207     glPushMatrix();
208     glTranslatef(-390.5, -30.5, 0.0);
209     DrawStrokeString(GLUT_STROKE_ROMAN, string);
210     glPopMatrix();
211 
212     glPopMatrix();
213 
214     glFlush();
215 
216     if (doubleBuffer) {
217 	glutSwapBuffers();
218     }
219 }
220 
Args(int argc,char ** argv)221 static GLenum Args(int argc, char **argv)
222 {
223     GLint i;
224 
225     rgb = GL_TRUE;
226     doubleBuffer = GL_FALSE;
227 
228     for (i = 1; i < argc; i++) {
229 	if (strcmp(argv[i], "-ci") == 0) {
230 	    rgb = GL_FALSE;
231 	} else if (strcmp(argv[i], "-rgb") == 0) {
232 	    rgb = GL_TRUE;
233 	} else if (strcmp(argv[i], "-sb") == 0) {
234 	    doubleBuffer = GL_FALSE;
235 	} else if (strcmp(argv[i], "-db") == 0) {
236 	    doubleBuffer = GL_TRUE;
237 	} else {
238 	    printf("%s (Bad option).\n", argv[i]);
239 	    return GL_FALSE;
240 	}
241     }
242     return GL_TRUE;
243 }
244 
main(int argc,char ** argv)245 int main(int argc, char **argv)
246 {
247     glutInit(&argc, argv);
248 
249     if (Args(argc, argv) == GL_FALSE) {
250 	exit(1);
251     }
252 
253     glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400);
254 
255     windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
256     windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
257     glutInitDisplayMode(windType);
258 
259     if (glutCreateWindow("Font Test") == GL_FALSE) {
260 	exit(1);
261     }
262 
263     InitMap();
264 
265     Init();
266 
267     glutReshapeFunc(Reshape);
268     glutKeyboardFunc(Key);
269     glutSpecialFunc(Key2);
270     glutDisplayFunc(Draw);
271     glutMainLoop();
272 	return 0;
273 }
274