Mercurial > sdl-ios-xcode
comparison Xcode/TemplatesForProjectBuilder/SDL OpenGL Application/atlantis/atlantis.c @ 2213:59a667370c57
make indent
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Tue, 24 Jul 2007 18:46:45 +0000 |
parents | d63e9f5944ae |
children | 4d2d0548f5b2 |
comparison
equal
deleted
inserted
replaced
2212:fdadda42d4d4 | 2213:59a667370c57 |
---|---|
52 | 52 |
53 GLboolean Timing = GL_TRUE; | 53 GLboolean Timing = GL_TRUE; |
54 | 54 |
55 int w_win = 640; | 55 int w_win = 640; |
56 int h_win = 480; | 56 int h_win = 480; |
57 GLint count = 0; | 57 GLint count = 0; |
58 GLenum StrMode = GL_VENDOR; | 58 GLenum StrMode = GL_VENDOR; |
59 | 59 |
60 GLboolean moving; | 60 GLboolean moving; |
61 | 61 |
62 static double mtime(void) | 62 static double |
63 { | 63 mtime(void) |
64 struct timeval tk_time; | 64 { |
65 struct timezone tz; | 65 struct timeval tk_time; |
66 | 66 struct timezone tz; |
67 gettimeofday(&tk_time, &tz); | 67 |
68 | 68 gettimeofday(&tk_time, &tz); |
69 return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec; | 69 |
70 } | 70 return 4294.967296 * tk_time.tv_sec + 0.000001 * tk_time.tv_usec; |
71 | 71 } |
72 static double filter(double in, double *save) | 72 |
73 { | 73 static double |
74 static double k1 = 0.9; | 74 filter(double in, double *save) |
75 static double k2 = 0.05; | 75 { |
76 | 76 static double k1 = 0.9; |
77 save[3] = in; | 77 static double k2 = 0.05; |
78 save[1] = save[0]*k1 + k2*(save[3] + save[2]); | 78 |
79 | 79 save[3] = in; |
80 save[0]=save[1]; | 80 save[1] = save[0] * k1 + k2 * (save[3] + save[2]); |
81 save[2]=save[3]; | 81 |
82 | 82 save[0] = save[1]; |
83 return(save[1]); | 83 save[2] = save[3]; |
84 } | 84 |
85 | 85 return (save[1]); |
86 void DrawStr(const char *str) | 86 } |
87 { | 87 |
88 GLint i = 0; | 88 void |
89 | 89 DrawStr(const char *str) |
90 if(!str) return; | 90 { |
91 | 91 GLint i = 0; |
92 while(str[i]) | 92 |
93 { | 93 if (!str) |
94 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]); | 94 return; |
95 i++; | 95 |
96 } | 96 while (str[i]) { |
97 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]); | |
98 i++; | |
99 } | |
97 } | 100 } |
98 | 101 |
99 void | 102 void |
100 InitFishs(void) | 103 InitFishs(void) |
101 { | 104 { |
132 } | 135 } |
133 | 136 |
134 void | 137 void |
135 Atlantis_Init(void) | 138 Atlantis_Init(void) |
136 { | 139 { |
137 static float ambient[] = {0.2, 0.2, 0.2, 1.0}; | 140 static float ambient[] = { 0.2, 0.2, 0.2, 1.0 }; |
138 static float diffuse[] = {1.0, 1.0, 1.0, 1.0}; | 141 static float diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; |
139 static float position[] = {0.0, 1.0, 0.0, 0.0}; | 142 static float position[] = { 0.0, 1.0, 0.0, 0.0 }; |
140 static float mat_shininess[] = {90.0}; | 143 static float mat_shininess[] = { 90.0 }; |
141 static float mat_specular[] = {0.8, 0.8, 0.8, 1.0}; | 144 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}; | 145 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}; | 146 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}; | 147 static float lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 }; |
145 static float lmodel_localviewer[] = {0.0}; | 148 static float lmodel_localviewer[] = { 0.0 }; |
146 //GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0}; | 149 //GLfloat map1[4] = {0.0, 0.0, 0.0, 0.0}; |
147 //GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0}; | 150 //GLfloat map2[4] = {0.0, 0.0, 0.0, 0.0}; |
148 static float fog_color[] = {0.0, 0.5, 0.9, 1.0}; | 151 static float fog_color[] = { 0.0, 0.5, 0.9, 1.0 }; |
149 | 152 |
150 glFrontFace(GL_CCW); | 153 glFrontFace(GL_CCW); |
151 | 154 |
152 glDepthFunc(GL_LESS); | 155 glDepthFunc(GL_LESS); |
153 glEnable(GL_DEPTH_TEST); | 156 glEnable(GL_DEPTH_TEST); |
166 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); | 169 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); |
167 | 170 |
168 InitFishs(); | 171 InitFishs(); |
169 | 172 |
170 glEnable(GL_FOG); | 173 glEnable(GL_FOG); |
171 glFogi(GL_FOG_MODE, GL_EXP); | 174 glFogi(GL_FOG_MODE, GL_EXP); |
172 glFogf(GL_FOG_DENSITY, 0.0000025); | 175 glFogf(GL_FOG_DENSITY, 0.0000025); |
173 glFogfv(GL_FOG_COLOR, fog_color); | 176 glFogfv(GL_FOG_COLOR, fog_color); |
174 | 177 |
175 glClearColor(0.0, 0.5, 0.9, 1.0); | 178 glClearColor(0.0, 0.5, 0.9, 1.0); |
176 } | 179 } |
177 | 180 |
178 void | 181 void |
179 Atlantis_Reshape(int width, int height) | 182 Atlantis_Reshape(int width, int height) |
180 { | 183 { |
181 w_win = width; | 184 w_win = width; |
182 h_win = height; | 185 h_win = height; |
183 | 186 |
184 glViewport(0, 0, width, height); | 187 glViewport(0, 0, width, height); |
185 | 188 |
186 glMatrixMode(GL_PROJECTION); | 189 glMatrixMode(GL_PROJECTION); |
187 glLoadIdentity(); | 190 glLoadIdentity(); |
188 gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, 300000.0); | 191 gluPerspective(60.0, (GLfloat) width / (GLfloat) height, 20000.0, |
192 300000.0); | |
189 glMatrixMode(GL_MODELVIEW); | 193 glMatrixMode(GL_MODELVIEW); |
190 } | 194 } |
191 | 195 |
192 void | 196 void |
193 Atlantis_Animate(void) | 197 Atlantis_Animate(void) |
210 void | 214 void |
211 Atlantis_Key(unsigned char key, int x, int y) | 215 Atlantis_Key(unsigned char key, int x, int y) |
212 { | 216 { |
213 switch (key) { | 217 switch (key) { |
214 case 't': | 218 case 't': |
215 Timing = !Timing; | 219 Timing = !Timing; |
216 break; | 220 break; |
217 case ' ': | 221 case ' ': |
218 switch(StrMode) | 222 switch (StrMode) { |
219 { | 223 case GL_EXTENSIONS: |
220 case GL_EXTENSIONS: | 224 StrMode = GL_VENDOR; |
221 StrMode = GL_VENDOR; | 225 break; |
222 break; | 226 case GL_VENDOR: |
223 case GL_VENDOR: | 227 StrMode = GL_RENDERER; |
224 StrMode = GL_RENDERER; | 228 break; |
225 break; | 229 case GL_RENDERER: |
226 case GL_RENDERER: | 230 StrMode = GL_VERSION; |
227 StrMode = GL_VERSION; | 231 break; |
228 break; | 232 case GL_VERSION: |
229 case GL_VERSION: | 233 StrMode = GL_EXTENSIONS; |
230 StrMode = GL_EXTENSIONS; | 234 break; |
231 break; | 235 } |
232 } | 236 break; |
233 break; | 237 case 27: /* Esc will quit */ |
234 case 27: /* Esc will quit */ | |
235 exit(1); | 238 exit(1); |
236 break; | 239 break; |
237 case 's': /* "s" start animation */ | 240 case 's': /* "s" start animation */ |
238 moving = GL_TRUE; | 241 moving = GL_TRUE; |
239 //glutIdleFunc(Animate); | 242 //glutIdleFunc(Animate); |
240 break; | 243 break; |
241 case 'a': /* "a" stop animation */ | 244 case 'a': /* "a" stop animation */ |
242 moving = GL_FALSE; | 245 moving = GL_FALSE; |
243 //glutIdleFunc(NULL); | 246 //glutIdleFunc(NULL); |
244 break; | 247 break; |
245 case '.': /* "." will advance frame */ | 248 case '.': /* "." will advance frame */ |
246 if (!moving) { | 249 if (!moving) { |
247 Atlantis_Animate(); | 250 Atlantis_Animate(); |
248 } | 251 } |
249 } | 252 } |
250 } | 253 } |
254 | |
251 /* | 255 /* |
252 void Display(void) | 256 void Display(void) |
253 { | 257 { |
254 static float P123[3] = {-448.94, -203.14, 9499.60}; | 258 static float P123[3] = {-448.94, -203.14, 9499.60}; |
255 static float P124[3] = {-442.64, -185.20, 9528.07}; | 259 static float P124[3] = {-442.64, -185.20, 9528.07}; |
271 | 275 |
272 void | 276 void |
273 Atlantis_Display(void) | 277 Atlantis_Display(void) |
274 { | 278 { |
275 int i; | 279 int i; |
276 static double th[4] = {0.0, 0.0, 0.0, 0.0}; | 280 static double th[4] = { 0.0, 0.0, 0.0, 0.0 }; |
277 static double t1 = 0.0, t2 = 0.0, t; | 281 static double t1 = 0.0, t2 = 0.0, t; |
278 char num_str[128]; | 282 char num_str[128]; |
279 | 283 |
280 t1 = t2; | 284 t1 = t2; |
281 | 285 |
282 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 286 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
283 | 287 |
284 for (i = 0; i < NUM_SHARKS; i++) { | 288 for (i = 0; i < NUM_SHARKS; i++) { |
301 glPushMatrix(); | 305 glPushMatrix(); |
302 FishTransform(&babyWhale); | 306 FishTransform(&babyWhale); |
303 glScalef(0.45, 0.45, 0.3); | 307 glScalef(0.45, 0.45, 0.3); |
304 DrawWhale(&babyWhale); | 308 DrawWhale(&babyWhale); |
305 glPopMatrix(); | 309 glPopMatrix(); |
306 | 310 |
307 if(Timing) | 311 if (Timing) { |
308 { | 312 t2 = mtime(); |
309 t2 = mtime(); | 313 t = t2 - t1; |
310 t = t2 - t1; | 314 if (t > 0.0001) |
311 if(t > 0.0001) t = 1.0 / t; | 315 t = 1.0 / t; |
312 | 316 |
313 glDisable(GL_LIGHTING); | 317 glDisable(GL_LIGHTING); |
314 //glDisable(GL_DEPTH_TEST); | 318 //glDisable(GL_DEPTH_TEST); |
315 | 319 |
316 glColor3f(1.0, 0.0, 0.0); | 320 glColor3f(1.0, 0.0, 0.0); |
317 | 321 |
318 glMatrixMode (GL_PROJECTION); | 322 glMatrixMode(GL_PROJECTION); |
319 glPushMatrix(); | 323 glPushMatrix(); |
320 glLoadIdentity(); | 324 glLoadIdentity(); |
321 glOrtho(0, w_win, 0, h_win, -10.0, 10.0); | 325 glOrtho(0, w_win, 0, h_win, -10.0, 10.0); |
322 | 326 |
323 glRasterPos2f(5.0, 5.0); | 327 glRasterPos2f(5.0, 5.0); |
324 | 328 |
325 switch(StrMode) | 329 switch (StrMode) { |
326 { | 330 case GL_VENDOR: |
327 case GL_VENDOR: | 331 sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), |
328 sprintf(num_str, "%0.2f Hz, %dx%d, VENDOR: ", filter(t, th), w_win, h_win); | 332 w_win, h_win); |
329 DrawStr(num_str); | 333 DrawStr(num_str); |
330 DrawStr(glGetString(GL_VENDOR)); | 334 DrawStr(glGetString(GL_VENDOR)); |
331 break; | 335 break; |
332 case GL_RENDERER: | 336 case GL_RENDERER: |
333 sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), w_win, h_win); | 337 sprintf(num_str, "%0.2f Hz, %dx%d, RENDERER: ", filter(t, th), |
334 DrawStr(num_str); | 338 w_win, h_win); |
335 DrawStr(glGetString(GL_RENDERER)); | 339 DrawStr(num_str); |
336 break; | 340 DrawStr(glGetString(GL_RENDERER)); |
337 case GL_VERSION: | 341 break; |
338 sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), w_win, h_win); | 342 case GL_VERSION: |
339 DrawStr(num_str); | 343 sprintf(num_str, "%0.2f Hz, %dx%d, VERSION: ", filter(t, th), |
340 DrawStr(glGetString(GL_VERSION)); | 344 w_win, h_win); |
341 break; | 345 DrawStr(num_str); |
342 case GL_EXTENSIONS: | 346 DrawStr(glGetString(GL_VERSION)); |
343 sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), w_win, h_win); | 347 break; |
344 DrawStr(num_str); | 348 case GL_EXTENSIONS: |
345 DrawStr(glGetString(GL_EXTENSIONS)); | 349 sprintf(num_str, "%0.2f Hz, %dx%d, EXTENSIONS: ", filter(t, th), |
346 break; | 350 w_win, h_win); |
347 } | 351 DrawStr(num_str); |
348 | 352 DrawStr(glGetString(GL_EXTENSIONS)); |
349 glPopMatrix(); | 353 break; |
350 glMatrixMode(GL_MODELVIEW); | 354 } |
351 | 355 |
352 glEnable(GL_LIGHTING); | 356 glPopMatrix(); |
353 //glEnable(GL_DEPTH_TEST); | 357 glMatrixMode(GL_MODELVIEW); |
354 } | 358 |
355 | 359 glEnable(GL_LIGHTING); |
360 //glEnable(GL_DEPTH_TEST); | |
361 } | |
362 | |
356 count++; | 363 count++; |
357 | 364 |
358 glutSwapBuffers(); | 365 glutSwapBuffers(); |
359 } | 366 } |
360 | 367 |