nvfx: expose GLSL
[mesa/mesa-lb.git] / progs / samples / font.c
bloba0091a65d7973585af9e2a55ad8c2244c1ac9f52
1 /*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
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.
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.
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.
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <GL/glut.h>
31 #define OPENGL_WIDTH 24
32 #define OPENGL_HEIGHT 13
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;
42 #include "tkmap.c"
45 static void DrawBitmapString(void *font, const char *string)
47 int i;
49 for (i = 0; string[i]; i++)
50 glutBitmapCharacter(font, string[i]);
53 static void DrawStrokeString(void *font, const char *string)
55 int i;
57 for (i = 0; string[i]; i++)
58 glutStrokeCharacter(font, string[i]);
61 static void Init(void)
64 glClearColor(0.0, 0.0, 0.0, 0.0);
65 glClearIndex(0.0);
68 static void Reshape(int width, int height)
71 glViewport(0, 0, (GLint)width, (GLint)height);
73 glMatrixMode(GL_PROJECTION);
74 glLoadIdentity();
75 glOrtho(-400.0, 400.0, -200.0, 200.0, -400.0, 400.0);
76 glMatrixMode(GL_MODELVIEW);
79 static void Key2(int key, int x, int y)
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;
99 glutPostRedisplay();
102 static void Key(unsigned char key, int x, int y)
105 switch (key) {
106 case 27:
107 exit(1);
109 case 'n':
110 shiftZ += 20.0;
111 break;
112 case 'm':
113 shiftZ -= 20.0;
114 break;
116 case 'q':
117 scaleX -= 0.1;
118 if (scaleX < 0.1) {
119 scaleX = 0.1;
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;
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;
139 break;
140 case 'x':
141 scaleZ += 0.1;
142 break;
144 case 'e':
145 angleX -= 5.0;
146 if (angleX < 0.0) {
147 angleX = 360.0 + angleX;
149 break;
150 case 'r':
151 angleX += 5.0;
152 if (angleX > 360.0) {
153 angleX = angleX - 360.0;
155 break;
156 case 'd':
157 angleY -= 5.0;
158 if (angleY < 0.0) {
159 angleY = 360.0 + angleY;
161 break;
162 case 'f':
163 angleY += 5.0;
164 if (angleY > 360.0) {
165 angleY = angleY - 360.0;
167 break;
168 case 'c':
169 angleZ -= 5.0;
170 if (angleZ < 0.0) {
171 angleZ = 360.0 + angleZ;
173 break;
174 case 'v':
175 angleZ += 5.0;
176 if (angleZ > 360.0) {
177 angleZ = angleZ - 360.0;
179 break;
180 default:
181 return;
184 glutPostRedisplay();
187 static void Draw(void)
190 glClear(GL_COLOR_BUFFER_BIT);
192 SetColor(COLOR_WHITE);
194 glPushMatrix();
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);
202 glPushMatrix();
203 glRasterPos2f(-390.5, 0.5);
204 DrawBitmapString(GLUT_BITMAP_9_BY_15, string);
205 glPopMatrix();
207 glPushMatrix();
208 glTranslatef(-390.5, -30.5, 0.0);
209 DrawStrokeString(GLUT_STROKE_ROMAN, string);
210 glPopMatrix();
212 glPopMatrix();
214 glFlush();
216 if (doubleBuffer) {
217 glutSwapBuffers();
221 static GLenum Args(int argc, char **argv)
223 GLint i;
225 rgb = GL_TRUE;
226 doubleBuffer = GL_FALSE;
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;
242 return GL_TRUE;
245 int main(int argc, char **argv)
247 glutInit(&argc, argv);
249 if (Args(argc, argv) == GL_FALSE) {
250 exit(1);
253 glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400);
255 windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
256 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
257 glutInitDisplayMode(windType);
259 if (glutCreateWindow("Font Test") == GL_FALSE) {
260 exit(1);
263 InitMap();
265 Init();
267 glutReshapeFunc(Reshape);
268 glutKeyboardFunc(Key);
269 glutSpecialFunc(Key2);
270 glutDisplayFunc(Draw);
271 glutMainLoop();
272 return 0;