annotate Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/atlantis/atlantis.c @ 3331:d44a0a913aa2

Eric Wing to Sam Lots of fixes. Fixed missing power management building. Added template icons to the project templates. DocSet stuff Documentation fixes.. Fixed all the SDLtests. (Lots of tedious work.) It now depends on the static library target for convenience so I am not going to remove it from the SDL xcode project.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 01 Oct 2009 15:30:26 +0000
parents
children
rev   line source
3331
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /* Copyright (c) Mark J. Kilgard, 1994. */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 /**
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * ALL RIGHTS RESERVED
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * Permission to use, copy, modify, and distribute this software for
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * any purpose and without fee is hereby granted, provided that the above
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * copyright notice appear in all copies and that both the copyright notice
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * and this permission notice appear in supporting documentation, and that
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 * the name of Silicon Graphics, Inc. not be used in advertising
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * or publicity pertaining to distribution of the software without specific,
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * written prior permission.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 *
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 *
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 * US Government Users Restricted Rights
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * Use, duplication, or disclosure by the Government is subject to
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 * clause at DFARS 252.227-7013 and/or in similar or successor
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 * clauses in the FAR or the DOD or NASA FAR Supplement.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 * Unpublished-- rights reserved under the copyright laws of the
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 * United States. Contractor/manufacturer is Silicon Graphics,
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 *
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include <stdio.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include <stdlib.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include <string.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #include <math.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #include <sys/time.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 #include <GLUT/glut.h>
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include "atlantis.h"
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 fishRec sharks[NUM_SHARKS];
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 fishRec momWhale;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 fishRec babyWhale;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 fishRec dolph;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 GLboolean Timing = GL_TRUE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 int w_win = 640;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 int h_win = 480;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 GLint count = 0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 GLenum StrMode = GL_VENDOR;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 GLboolean moving;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 static double mtime(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 struct timeval tk_time;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 struct timezone tz;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 gettimeofday(&tk_time, &tz);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 static double filter(double in, double *save)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 static double k1 = 0.9;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 static double k2 = 0.05;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 save[3] = in;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 save[1] = save[0]*k1 + k2*(save[3] + save[2]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 save[0]=save[1];
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 save[2]=save[3];
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 return(save[1]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 void DrawStr(const char *str)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 GLint i = 0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 if(!str) return;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 while(str[i])
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 i++;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 InitFishs(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 int i;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 for (i = 0; i < NUM_SHARKS; i++) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 sharks[i].x = 70000.0 + rand() % 6000;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 sharks[i].y = rand() % 6000;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 sharks[i].z = rand() % 6000;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 sharks[i].psi = rand() % 360 - 180.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 sharks[i].v = 1.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 dolph.x = 30000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 dolph.y = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 dolph.z = 6000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 dolph.psi = 90.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 dolph.theta = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 dolph.v = 3.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 momWhale.x = 70000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 momWhale.y = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 momWhale.z = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 momWhale.psi = 90.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 momWhale.theta = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 momWhale.v = 3.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 babyWhale.x = 60000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 babyWhale.y = -2000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 babyWhale.z = -2000.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 babyWhale.psi = 90.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 babyWhale.theta = 0.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 babyWhale.v = 3.0;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 Atlantis_Init(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 static float ambient[] = {0.2, 0.2, 0.2, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 static float diffuse[] = {1.0, 1.0, 1.0, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 static float position[] = {0.0, 1.0, 0.0, 0.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 static float mat_shininess[] = {90.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 static float mat_specular[] = {0.8, 0.8, 0.8, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 static float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 static float mat_ambient[] = {0.3, 0.4, 0.5, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 static float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 static float lmodel_localviewer[] = {0.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 //GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 //GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 static float fog_color[] = {0.0, 0.5, 0.9, 1.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 glFrontFace(GL_CCW);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 glDepthFunc(GL_LESS);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 glEnable(GL_DEPTH_TEST);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 glLightfv(GL_LIGHT0, GL_POSITION, position);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 glEnable(GL_LIGHTING);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 glEnable(GL_LIGHT0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 InitFishs();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 glEnable(GL_FOG);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 glFogi(GL_FOG_MODE, GL_EXP);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 glFogf(GL_FOG_DENSITY, 0.0000025);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 glFogfv(GL_FOG_COLOR, fog_color);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 glClearColor(0.0, 0.5, 0.9, 1.0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 Atlantis_Reshape(int width, int height)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 w_win = width;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 h_win = height;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 glViewport(0, 0, width, height);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 glMatrixMode(GL_PROJECTION);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 glLoadIdentity();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, 300000.0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 glMatrixMode(GL_MODELVIEW);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 Atlantis_Animate(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 int i;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 for (i = 0; i < NUM_SHARKS; i++) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 SharkPilot(&sharks[i]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 SharkMiss(i);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 WhalePilot(&dolph);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 dolph.phi++;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 //glutPostRedisplay();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 WhalePilot(&momWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 momWhale.phi++;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 WhalePilot(&babyWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 babyWhale.phi++;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 Atlantis_Key(unsigned char key, int x, int y)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 switch (key) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 case 't':
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 Timing = !Timing;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 case ' ':
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 switch(StrMode)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 case GL_EXTENSIONS:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 StrMode = GL_VENDOR;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 case GL_VENDOR:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 StrMode = GL_RENDERER;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 case GL_RENDERER:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 StrMode = GL_VERSION;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 case GL_VERSION:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 StrMode = GL_EXTENSIONS;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 case 27: /* Esc will quit */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 exit(1);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 case 's': /* "s" start animation */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 moving = GL_TRUE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 //glutIdleFunc(Animate);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 case 'a': /* "a" stop animation */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 moving = GL_FALSE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 //glutIdleFunc(NULL);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 case '.': /* "." will advance frame */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 if (!moving) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 Atlantis_Animate();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 /*
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 void Display(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 static float P123[3] = {-448.94, -203.14, 9499.60};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 static float P124[3] = {-442.64, -185.20, 9528.07};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 static float P125[3] = {-441.07, -148.05, 9528.07};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 static float P126[3] = {-443.43, -128.84, 9499.60};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 static float P127[3] = {-456.87, -146.78, 9466.67};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 static float P128[3] = {-453.68, -183.93, 9466.67};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 FishTransform(&dolph);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 DrawDolphin(&dolph);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 glutSwapBuffers();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 */
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 Atlantis_Display(void)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 int i;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 static double th[4] = {0.0, 0.0, 0.0, 0.0};
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 static double t1 = 0.0, t2 = 0.0, t;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 char num_str[128];
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 t1 = t2;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 for (i = 0; i < NUM_SHARKS; i++) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 FishTransform(&sharks[i]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 DrawShark(&sharks[i]);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 FishTransform(&dolph);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 DrawDolphin(&dolph);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 FishTransform(&momWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 DrawWhale(&momWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 FishTransform(&babyWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 glScalef(0.45, 0.45, 0.3);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 DrawWhale(&babyWhale);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 if(Timing)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 t2 = mtime();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 t = t2 - t1;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 if(t > 0.0001) t = 1.0 / t;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 glDisable(GL_LIGHTING);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 //glDisable(GL_DEPTH_TEST);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 glColor3f(1.0, 0.0, 0.0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 glMatrixMode (GL_PROJECTION);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 glPushMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 glLoadIdentity();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 glOrtho(0, w_win, 0, h_win, -10.0, 10.0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 glRasterPos2f(5.0, 5.0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 switch(StrMode)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 case GL_VENDOR:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 DrawStr(num_str);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 DrawStr(glGetString(GL_VENDOR));
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 case GL_RENDERER:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 DrawStr(num_str);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 DrawStr(glGetString(GL_RENDERER));
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 case GL_VERSION:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 DrawStr(num_str);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 DrawStr(glGetString(GL_VERSION));
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 case GL_EXTENSIONS:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 DrawStr(num_str);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 DrawStr(glGetString(GL_EXTENSIONS));
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 glPopMatrix();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 glMatrixMode(GL_MODELVIEW);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 glEnable(GL_LIGHTING);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 //glEnable(GL_DEPTH_TEST);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 count++;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 glutSwapBuffers();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 /*
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 Visible(int state)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 if (state == GLUT_VISIBLE) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 if (moving)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 glutIdleFunc(Animate);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 } else {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 if (moving)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 glutIdleFunc(NULL);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 timingSelect(int value)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 switch(value)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 case 1:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 StrMode = GL_VENDOR;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 case 2:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 StrMode = GL_RENDERER;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 case 3:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 StrMode = GL_VERSION;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 case 4:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 StrMode = GL_EXTENSIONS;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 void
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 menuSelect(int value)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 switch (value) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 case 1:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 moving = GL_TRUE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 glutIdleFunc(Animate);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 case 2:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 moving = GL_FALSE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 glutIdleFunc(NULL);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 case 4:
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 exit(0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 break;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 int
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 main(int argc, char **argv)
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 GLboolean fullscreen = GL_FALSE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 GLint time_menu;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 srand(0);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 glutInit(&argc, argv);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 if (argc > 1 && !strcmp(argv[1], "-w"))
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 fullscreen = GL_FALSE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 //glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 glutInitDisplayString("rgba double depth=24");
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 if (fullscreen) {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 glutGameModeString("1024x768:32");
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 glutEnterGameMode();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 } else {
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 glutInitWindowSize(320, 240);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 glutCreateWindow("Atlantis Timing");
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 Init();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 glutDisplayFunc(Display);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 glutReshapeFunc(Reshape);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 glutKeyboardFunc(Key);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 moving = GL_TRUE;
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 glutIdleFunc(Animate);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 glutVisibilityFunc(Visible);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 time_menu = glutCreateMenu(timingSelect);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 glutAddMenuEntry("GL_VENDOR", 1);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 glutAddMenuEntry("GL_RENDERER", 2);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 glutAddMenuEntry("GL_VERSION", 3);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 glutAddMenuEntry("GL_EXTENSIONS", 4);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 glutCreateMenu(menuSelect);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 glutAddMenuEntry("Start motion", 1);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 glutAddMenuEntry("Stop motion", 2);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 glutAddSubMenu("Timing Mode", time_menu);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 glutAddMenuEntry("Quit", 4);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 //glutAttachMenu(GLUT_RIGHT_BUTTON);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 glutAttachMenu(GLUT_RIGHT_BUTTON);
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 glutMainLoop();
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 return 0; // ANSI C requires main to return int.
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 }
d44a0a913aa2 Eric Wing to Sam
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 */