2 /* Copyright (c) Mark J. Kilgard, 1994. */
5 * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
7 * Permission to use, copy, modify, and distribute this software for
8 * any purpose and without fee is hereby granted, provided that the above
9 * copyright notice appear in all copies and that both the copyright notice
10 * and this permission notice appear in supporting documentation, and that
11 * the name of Silicon Graphics, Inc. not be used in advertising
12 * or publicity pertaining to distribution of the software without specific,
13 * written prior permission.
15 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
28 * US Government Users Restricted Rights
29 * Use, duplication, or disclosure by the Government is subject to
30 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
32 * clause at DFARS 252.227-7013 and/or in similar or successor
33 * clauses in the FAR or the DOD or NASA FAR Supplement.
34 * Unpublished-- rights reserved under the copyright laws of the
35 * United States. Contractor/manufacturer is Silicon Graphics,
36 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
45 #include <GLUT/glut.h>
48 fishRec sharks[NUM_SHARKS];
53 GLboolean Timing = GL_TRUE;
58 GLenum StrMode = GL_VENDOR;
62 static double mtime(void)
64 struct timeval tk_time;
67 gettimeofday(&tk_time, &tz);
69 return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec;
72 static double filter(double in, double *save)
74 static double k1 = 0.9;
75 static double k2 = 0.05;
78 save[1] = save[0]*k1 + k2*(save[3] + save[2]);
86 void DrawStr(const char *str)
94 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
104 for (i = 0; i < NUM_SHARKS; i++) {
105 sharks[i].x = 70000.0 + rand() % 6000;
106 sharks[i].y = rand() % 6000;
107 sharks[i].z = rand() % 6000;
108 sharks[i].psi = rand() % 360 - 180.0;
119 momWhale.x = 70000.0;
123 momWhale.theta = 0.0;
126 babyWhale.x = 60000.0;
127 babyWhale.y = -2000.0;
128 babyWhale.z = -2000.0;
129 babyWhale.psi = 90.0;
130 babyWhale.theta = 0.0;
137 static float ambient[] = {0.2, 0.2, 0.2, 1.0};
138 static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
139 static float position[] = {0.0, 1.0, 0.0, 0.0};
140 static float mat_shininess[] = {90.0};
141 static float mat_specular[] = {0.8, 0.8, 0.8, 1.0};
142 static float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0};
143 static float mat_ambient[] = {0.3, 0.4, 0.5, 1.0};
144 static float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0};
145 static float lmodel_localviewer[] = {0.0};
146 //GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0};
147 //GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0};
148 static float fog_color[] = {0.0, 0.5, 0.9, 1.0};
152 glDepthFunc(GL_LESS);
153 glEnable(GL_DEPTH_TEST);
155 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
156 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
157 glLightfv(GL_LIGHT0, GL_POSITION, position);
158 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
159 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
160 glEnable(GL_LIGHTING);
163 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
164 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
165 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
166 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
171 glFogi(GL_FOG_MODE, GL_EXP);
172 glFogf(GL_FOG_DENSITY, 0.0000025);
173 glFogfv(GL_FOG_COLOR, fog_color);
175 glClearColor(0.0, 0.5, 0.9, 1.0);
179 Atlantis_Reshape(int width, int height)
184 glViewport(0, 0, width, height);
186 glMatrixMode(GL_PROJECTION);
188 gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, 300000.0);
189 glMatrixMode(GL_MODELVIEW);
193 Atlantis_Animate(void)
197 for (i = 0; i < NUM_SHARKS; i++) {
198 SharkPilot(&sharks[i]);
203 //glutPostRedisplay();
204 WhalePilot(&momWhale);
206 WhalePilot(&babyWhale);
211 Atlantis_Key(unsigned char key, int x, int y)
224 StrMode = GL_RENDERER;
227 StrMode = GL_VERSION;
230 StrMode = GL_EXTENSIONS;
234 case 27: /* Esc will quit */
237 case 's': /* "s" start animation */
239 //glutIdleFunc(Animate);
241 case 'a': /* "a" stop animation */
243 //glutIdleFunc(NULL);
245 case '.': /* "." will advance frame */
254 static float P123[3] = {-448.94, -203.14, 9499.60};
255 static float P124[3] = {-442.64, -185.20, 9528.07};
256 static float P125[3] = {-441.07, -148.05, 9528.07};
257 static float P126[3] = {-443.43, -128.84, 9499.60};
258 static float P127[3] = {-456.87, -146.78, 9466.67};
259 static float P128[3] = {-453.68, -183.93, 9466.67};
261 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
264 FishTransform(&dolph);
273 Atlantis_Display(void)
276 static double th[4] = {0.0, 0.0, 0.0, 0.0};
277 static double t1 = 0.0, t2 = 0.0, t;
282 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
284 for (i = 0; i < NUM_SHARKS; i++) {
286 FishTransform(&sharks[i]);
287 DrawShark(&sharks[i]);
292 FishTransform(&dolph);
297 FishTransform(&momWhale);
298 DrawWhale(&momWhale);
302 FishTransform(&babyWhale);
303 glScalef(0.45, 0.45, 0.3);
304 DrawWhale(&babyWhale);
311 if(t > 0.0001) t = 1.0 / t;
313 glDisable(GL_LIGHTING);
314 //glDisable(GL_DEPTH_TEST);
316 glColor3f(1.0, 0.0, 0.0);
318 glMatrixMode (GL_PROJECTION);
321 glOrtho(0, w_win, 0, h_win, -10.0, 10.0);
323 glRasterPos2f(5.0, 5.0);
328 sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win);
330 DrawStr(glGetString(GL_VENDOR));
333 sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win);
335 DrawStr(glGetString(GL_RENDERER));
338 sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win);
340 DrawStr(glGetString(GL_VERSION));
343 sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win);
345 DrawStr(glGetString(GL_EXTENSIONS));
350 glMatrixMode(GL_MODELVIEW);
352 glEnable(GL_LIGHTING);
353 //glEnable(GL_DEPTH_TEST);
365 if (state == GLUT_VISIBLE) {
367 glutIdleFunc(Animate);
376 timingSelect(int value)
384 StrMode = GL_RENDERER;
387 StrMode = GL_VERSION;
390 StrMode = GL_EXTENSIONS;
396 menuSelect(int value)
401 glutIdleFunc(Animate);
414 main(int argc, char **argv)
416 GLboolean fullscreen = GL_FALSE;
421 glutInit(&argc, argv);
422 if (argc > 1 && !strcmp(argv[1], "-w"))
423 fullscreen = GL_FALSE;
425 //glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
426 glutInitDisplayString("rgba double depth=24");
428 glutGameModeString("1024x768:32");
431 glutInitWindowSize(320, 240);
432 glutCreateWindow("Atlantis Timing");
435 glutDisplayFunc(Display);
436 glutReshapeFunc(Reshape);
437 glutKeyboardFunc(Key);
439 glutIdleFunc(Animate);
440 glutVisibilityFunc(Visible);
442 time_menu = glutCreateMenu(timingSelect);
443 glutAddMenuEntry("GL_VENDOR", 1);
444 glutAddMenuEntry("GL_RENDERER", 2);
445 glutAddMenuEntry("GL_VERSION", 3);
446 glutAddMenuEntry("GL_EXTENSIONS", 4);
448 glutCreateMenu(menuSelect);
449 glutAddMenuEntry("Start motion", 1);
450 glutAddMenuEntry("Stop motion", 2);
451 glutAddSubMenu("Timing Mode", time_menu);
452 glutAddMenuEntry("Quit", 4);
454 //glutAttachMenu(GLUT_RIGHT_BUTTON);
455 glutAttachMenu(GLUT_RIGHT_BUTTON);
457 return 0; // ANSI C requires main to return int.