]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTmain.cxx
Fog tweaks.
[flightgear.git] / Main / GLUTmain.cxx
1 //
2 // GLUTmain.cxx -- top level sim routines
3 //
4 // Written by Curtis Olson for OpenGL, started May 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #ifdef HAVE_WINDOWS_H
31 #  include <windows.h>                     
32 #endif
33
34 #include <GL/glut.h>
35 #include <XGL/xgl.h>
36 #include <stdio.h>
37
38 #ifdef HAVE_STDLIB_H
39 #   include <stdlib.h>
40 #endif
41
42 #include <Include/fg_constants.h>  // for VERSION
43 #include <Include/general.h>
44
45 #include <Aircraft/aircraft.h>
46 #include <Astro/moon.hxx>
47 #include <Astro/planets.hxx>
48 #include <Astro/sky.hxx>
49 #include <Astro/stars.hxx>
50 #include <Astro/sun.hxx>
51 #include <Cockpit/cockpit.hxx>
52 #include <Debug/fg_debug.h>
53 #include <Joystick/joystick.h>
54 #include <Math/fg_geodesy.h>
55 #include <Math/mat3.h>
56 #include <Math/polar.h>
57 #include <Scenery/scenery.h>
58 #include <Scenery/tilemgr.hxx>
59 #include <Time/event.hxx>
60 #include <Time/fg_time.hxx>
61 #include <Time/fg_timer.hxx>
62 #include <Time/sunpos.hxx>
63 #include <Weather/weather.h>
64
65 #include "GLUTkey.hxx"
66 #include "fg_init.hxx"
67 #include "options.hxx"
68 #include "views.hxx"
69
70
71 // This is a record containing global housekeeping information
72 fgGENERAL general;
73
74 // view parameters
75 static GLfloat win_ratio = 1.0;
76 static GLint winWidth, winHeight;
77
78 // Another hack
79 int use_signals = 0;
80
81 // Yet another other hack. Used for my prototype instrument code. (Durk)
82 int displayInstruments; 
83
84 /*
85 // The following defines flight gear options. Because glutlib will also
86 // want to parse its own options, those options must not be included here
87 // or they will get parsed by the main program option parser. Hence case
88 // is significant for any option added that might be in conflict with
89 // glutlib's parser.
90 //
91 // glutlib parses for:
92 //    -display
93 //    -direct   (invalid in Win32)
94 //    -geometry
95 //    -gldebug
96 //    -iconized
97 //    -indirect (invalid in Win32)
98 //    -synce
99 //
100 // Note that glutlib depends upon strings while this program's
101 // option parser wants only initial characters followed by numbers
102 // or pathnames.
103 //
104 const char *fg_cmdargopts = "a:c:Hhp:r:v:x:?";
105 //
106 // Where
107 //   -a aircraftfilename    aircraft start over ride
108 //   -c0x0000 - 0xffffffff  debug class setting
109 //    H,h.? help on command line use (does not need Option struct)
110 //   -p  priority
111 //   -r flightgear          root path to program support files
112 //   -v0 -v1                initial view mode (hud/no_hud currently)
113 //   -xlogpathname          debug logfile name
114 //
115 // Defaults in arguments to indicate not set on command line.
116 // Program defaults set variables from constants if neither command
117 // options or environmental variables effect values.
118 //
119
120 char  acArgbuf          [ MAXPATH + 1] = "\0";
121 int   debugArgValue                    = -2;
122 int   priorityArgValue                 = -1;
123 char  rootArgbuf        [ MAXPATH + 1] = "\0";
124 int   viewArg                          = -1;
125 char  logArgbuf         [ MAXPATH + 1] = "\0";
126
127 // There is a reason for defining the option structs by name and then
128 // creating an array of pointers to options. C++ is unfriendly to
129 // initializing arrays of objects that are not built in types. Always
130 // look forward. (Besides, you can follow what is going on better and
131 // add or modify with greater security. -ch
132 //
133 Option aircraftOption = { 'a',
134                           OPT_STRING,
135                           acArgbuf,
136                           "Startup aircraft pathname override"
137                         };
138 Option debugOption    = { 'c',
139                           OPT_LHEX,       // Long int (32 bits)
140                           &debugArgValue,
141                           "Debug trace level"
142                         };
143 Option priorityOption = { 'p',
144                           OPT_INTEGER,
145                           &priorityArgValue,
146                           "Debug priority Threshold"
147                         };
148 Option rootOption     = { 'r',
149                           OPT_STRING,
150                           rootArgbuf,
151                           "Root directory for execution"
152                         };
153 Option hudOption      = { 'v',
154                           OPT_INTEGER,
155                           &viewArg,
156                           "View mode start" // Naked,HUD,Panel,Chase,Tower...
157                         };
158
159 // Only naked view and HUD are implemented at this time
160 Option logfileOption  = { 'x',
161                           OPT_STRING,
162                           logArgbuf,
163                           "Debug log file name"
164                         };
165
166 #define OptsDefined 6
167 Option *CmdLineOptions[ OptsDefined ] = {
168   &aircraftOption,
169   &debugOption,
170   &hudOption,
171   &priorityOption,
172   &rootOption,
173   &logfileOption
174   };
175
176 const char *DefaultRootDir  = "\\Flightgear";
177 const char *DefaultAircraft = "Navion.acf";
178 const char *DefaultDebuglog = "fgdebug.log";
179 const int   DefaultViewMode = HUD_VIEW;
180 */
181
182 // Debug defaults handled in fg_debug.c
183
184 // fgInitVisuals() -- Initialize various GL/view parameters
185 static void fgInitVisuals( void ) {
186     struct fgLIGHT *l;
187     struct fgWEATHER *w;
188
189     l = &cur_light_params;
190     w = &current_weather;
191
192     // xglDisable( GL_DITHER );
193
194     // If enabled, normal vectors specified with glNormal are scaled
195     // to unit length after transformation.  See glNormal.
196     xglEnable( GL_NORMALIZE );
197
198     xglEnable( GL_LIGHTING );
199     xglEnable( GL_LIGHT0 );
200     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
201
202     xglFogi (GL_FOG_MODE, GL_LINEAR);
203     xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
204     xglFogf (GL_FOG_END, w->visibility);
205     // xglFogf (GL_FOG_DENSITY, w->visibility);
206     xglHint (GL_FOG_HINT, GL_NICEST /* GL_FASTEST */ );
207
208     // draw wire frame
209     // xglPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
210 }
211
212
213 // Update the view volume, position, and orientation
214 static void fgUpdateViewParams( void ) {
215     fgFLIGHT *f;
216     struct fgLIGHT *l;
217     // struct fgTIME *t;
218     struct fgVIEW *v;
219
220     f = current_aircraft.flight;
221     l = &cur_light_params;
222     // t = &cur_time_params;
223     v = &current_view;
224
225     fgViewUpdate(f, v, l);
226
227     if (displayInstruments) {
228         xglViewport( 0, (GLint)(winHeight / 2 ) , 
229                      (GLint)winWidth, (GLint)winHeight / 2 );
230         // Tell GL we are about to modify the projection parameters
231         xglMatrixMode(GL_PROJECTION);
232         xglLoadIdentity();
233         gluPerspective(65.0, 2.0/win_ratio, 1.0, 100000.0);
234     } else {
235         xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight);
236         // Tell GL we are about to modify the projection parameters
237         xglMatrixMode(GL_PROJECTION);
238         xglLoadIdentity();
239         gluPerspective(65.0, 1.0/win_ratio, 10.0, 100000.0);
240     }
241
242     xglMatrixMode(GL_MODELVIEW);
243     xglLoadIdentity();
244     
245     // set up our view volume (default)
246     gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
247                v->view_pos.x + v->view_forward[0], 
248                v->view_pos.y + v->view_forward[1], 
249                v->view_pos.z + v->view_forward[2],
250                v->view_up[0], v->view_up[1], v->view_up[2]);
251
252     // look almost straight up (testing and eclipse watching)
253     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
254                v->view_pos.x + v->view_up[0] + .001, 
255                v->view_pos.y + v->view_up[1] + .001, 
256                v->view_pos.z + v->view_up[2] + .001,
257                v->view_up[0], v->view_up[1], v->view_up[2]); */
258
259     // lock view horizontally towards sun (testing)
260     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
261                v->view_pos.x + v->surface_to_sun[0], 
262                v->view_pos.y + v->surface_to_sun[1], 
263                v->view_pos.z + v->surface_to_sun[2],
264                v->view_up[0], v->view_up[1], v->view_up[2]); */
265
266     // lock view horizontally towards south (testing)
267     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
268                v->view_pos.x + v->surface_south[0], 
269                v->view_pos.y + v->surface_south[1], 
270                v->view_pos.z + v->surface_south[2],
271                v->view_up[0], v->view_up[1], v->view_up[2]); */
272
273     // set the sun position
274     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
275 }
276
277
278 // Draw a basic instrument panel
279 static void fgUpdateInstrViewParams( void ) {
280     xglViewport(0, 0 , (GLint)winWidth, (GLint)winHeight / 2);
281   
282     xglMatrixMode(GL_PROJECTION);
283     xglPushMatrix();
284   
285     xglLoadIdentity();
286     gluOrtho2D(0, 640, 0, 480);
287     xglMatrixMode(GL_MODELVIEW);
288     xglPushMatrix();
289     xglLoadIdentity();
290
291     xglColor3f(1.0, 1.0, 1.0);
292     xglIndexi(7);
293   
294     xglDisable(GL_DEPTH_TEST);
295     xglDisable(GL_LIGHTING);
296   
297     xglLineWidth(1);
298     xglColor3f (0.5, 0.5, 0.5);
299
300     xglBegin(GL_QUADS);
301     xglVertex2f(0.0, 0.00);
302     xglVertex2f(0.0, 480.0);
303     xglVertex2f(640.0,480.0);
304     xglVertex2f(640.0, 0.0);
305     xglEnd();
306
307     xglRectf(0.0,0.0, 640, 480);
308     xglEnable(GL_DEPTH_TEST);
309     xglEnable(GL_LIGHTING);
310     xglMatrixMode(GL_PROJECTION);
311     xglPopMatrix();
312     xglMatrixMode(GL_MODELVIEW);
313     xglPopMatrix();
314 }
315
316
317 // Update all Visuals (redraws anything graphics related)
318 static void fgRenderFrame( void ) {
319     struct fgLIGHT *l;
320     fgOPTIONS *o;
321     struct fgTIME *t;
322     struct fgVIEW *v;
323     double angle;
324     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
325     GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
326
327     l = &cur_light_params;
328     o = &current_options;
329     t = &cur_time_params;
330     v = &current_view;
331
332     // update view volume parameters
333     fgUpdateViewParams();
334
335     xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
336
337     // Tell GL we are switching to model view parameters
338     xglMatrixMode(GL_MODELVIEW);
339     // xglLoadIdentity();
340
341     // draw sky
342     xglDisable( GL_DEPTH_TEST );
343     xglDisable( GL_LIGHTING );
344     xglDisable( GL_CULL_FACE );
345     xglDisable( GL_FOG );
346     xglShadeModel( GL_SMOOTH );
347     fgSkyRender();
348
349     // setup transformation for drawing astronomical objects
350     xglPushMatrix();
351     // Translate to view position
352     xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
353     // Rotate based on gst (sidereal time)
354     angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
355     // printf("Rotating astro objects by %.2f degrees\n",angle);
356     xglRotatef( angle, 0.0, 0.0, -1.0 );
357
358     // draw stars and planets
359     fgStarsRender();
360     fgPlanetsRender();
361
362     // draw the sun
363     fgSunRender();
364
365     // render the moon
366     xglEnable( GL_LIGHTING );
367     // set lighting parameters
368     xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
369     xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
370     xglEnable( GL_CULL_FACE );
371     
372     // Let's try some blending technique's (Durk)
373     glEnable(GL_BLEND);
374     glBlendFunc(GL_ONE, GL_ONE);
375     fgMoonRender();
376     glDisable(GL_BLEND);
377
378     xglPopMatrix();
379
380     // draw scenery
381     xglShadeModel( /* GL_FLAT */ GL_SMOOTH ); 
382     xglEnable( GL_DEPTH_TEST );
383     xglEnable( GL_FOG );
384     xglFogfv (GL_FOG_COLOR, l->fog_color);
385     // set lighting parameters
386     xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
387     xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
388     // texture parameters
389     xglEnable( GL_TEXTURE_2D ); /* xglDisable( GL_TEXTURE_2D ); */
390     xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ) ;
391     xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) ;
392     xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
393     xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
394                       GL_LINEAR /* GL_LINEAR_MIPMAP_LINEAR */ ) ;
395     xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
396     xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
397     // set base color (I don't think this is doing anything here)
398     xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
399     xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
400
401     fgTileMgrRender();
402
403     xglDisable( GL_TEXTURE_2D );
404
405     // display HUD
406     if( o->hud_status ) {
407         fgCockpitUpdate();
408     }
409
410     // display instruments
411     if (displayInstruments) {
412         fgUpdateInstrViewParams();
413     }
414
415     xglutSwapBuffers();
416 }
417
418
419 // Update internal time dependent calculations (i.e. flight model)
420 void fgUpdateTimeDepCalcs(int multi_loop) {
421     fgFLIGHT *f;
422     struct fgTIME *t;
423     struct fgVIEW *v;
424     int i;
425
426     f = current_aircraft.flight;
427     t = &cur_time_params;
428     v = &current_view;
429
430     // update the flight model
431     if ( multi_loop < 0 ) {
432         multi_loop = DEFAULT_MULTILOOP;
433     }
434
435     // printf("updating flight model x %d\n", multi_loop);
436     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
437
438     // update the view angle
439     for ( i = 0; i < multi_loop; i++ ) {
440         if ( fabs(v->goal_view_offset - v->view_offset) < 0.05 ) {
441             v->view_offset = v->goal_view_offset;
442             break;
443         } else {
444             // move v->view_offset towards v->goal_view_offset
445             if ( v->goal_view_offset > v->view_offset ) {
446                 if ( v->goal_view_offset - v->view_offset < FG_PI ) {
447                     v->view_offset += 0.01;
448                 } else {
449                     v->view_offset -= 0.01;
450                 }
451             } else {
452                 if ( v->view_offset - v->goal_view_offset < FG_PI ) {
453                     v->view_offset -= 0.01;
454                 } else {
455                     v->view_offset += 0.01;
456                 }
457             }
458             if ( v->view_offset > FG_2PI ) {
459                 v->view_offset -= FG_2PI;
460             } else if ( v->view_offset < 0 ) {
461                 v->view_offset += FG_2PI;
462             }
463         }
464     }
465 }
466
467
468 void fgInitTimeDepCalcs( void ) {
469     // initialize timer
470
471 #ifdef HAVE_SETITIMER
472     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
473 #endif HAVE_SETITIMER
474
475 }
476
477
478 // What should we do when we have nothing else to do?  Let's get ready
479 // for the next move and update the display?
480 static void fgMainLoop( void ) {
481     static int remainder = 0;
482     int elapsed, multi_loop;
483     double cur_elev;
484     // double joy_x, joy_y;
485     // int joy_b1, joy_b2;
486     fgAIRCRAFT *a;
487     fgFLIGHT *f;
488     struct fgTIME *t;
489
490     fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
491     fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
492
493     a = &current_aircraft;
494     f = a->flight;
495     t = &cur_time_params;
496
497     // update "time"
498     fgTimeUpdate(f, t);
499
500     // Read joystick
501     /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
502     printf( "Joystick X %f  Y %f  B1 %d  B2 %d\n",  
503             joy_x, joy_y, joy_b1, joy_b2 );
504     fgElevSet( -joy_y );
505     fgAileronSet( joy_x ); */
506
507     // Calculate model iterations needed
508     elapsed = fgGetTimeInterval();
509     fgPrintf( FG_ALL, FG_BULK, 
510               "Time interval is = %d, previous remainder is = %d\n", 
511               elapsed, remainder);
512     fgPrintf( FG_ALL, FG_BULK, 
513               "--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
514     elapsed += remainder;
515
516     multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
517     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
518     fgPrintf( FG_ALL, FG_BULK, 
519               "Model iterations needed = %d, new remainder = %d\n", 
520               multi_loop, remainder);
521         
522     // Run flight model
523     if ( ! use_signals ) {
524         // flight model
525         fgUpdateTimeDepCalcs(multi_loop);
526     }
527
528     // I'm just sticking this here for now, it should probably move
529     // eventually
530     /* cur_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC, 
531                                FG_Latitude  * RAD_TO_ARCSEC); */
532     // there is no ground collision detection really, so for now I
533     // just hard code the ground elevation to be 0 */
534     cur_elev = 0;
535
536     // printf("Ground elevation is %.2f meters here.\n", cur_elev);
537     // FG_Runway_altitude = cur_elev * METER_TO_FEET;
538
539     if ( FG_Altitude * FEET_TO_METER < cur_elev + 3.758099) {
540         // set this here, otherwise if we set runway height above our
541         // current height we get a really nasty bounce.
542         FG_Runway_altitude = FG_Altitude - 3.758099;
543
544         // now set aircraft altitude above ground
545         FG_Altitude = cur_elev * METER_TO_FEET + 3.758099;
546         fgPrintf( FG_ALL, FG_BULK, "<*> resetting altitude to %.0f meters\n", 
547                FG_Altitude * FEET_TO_METER);
548     }
549
550     fgAircraftOutputCurrent(a);
551
552     // see if we need to load any new scenery tiles
553     fgTileMgrUpdate();
554
555     // Process/manage pending events
556     fgEventProcess();
557
558     // redraw display
559     fgRenderFrame();
560
561     fgPrintf( FG_ALL, FG_DEBUG, "\n");
562 }
563
564
565 // Handle new window size or exposure
566 static void fgReshape( int width, int height ) {
567     // Do this so we can call fgReshape(0,0) ourselves without having
568     // to know what the values of width & height are.
569     if ( (height > 0) && (width > 0) ) {
570         win_ratio = (GLfloat) height / (GLfloat) width;
571     }
572
573     winWidth = width;
574     winHeight = height;
575
576     // Inform gl of our view window size (now handled elsewhere)
577     // xglViewport(0, 0, (GLint)width, (GLint)height);
578     fgUpdateViewParams();
579     
580     // xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
581 }
582
583
584 // Initialize GLUT and define a main window
585 int fgGlutInit( int argc, char **argv ) {
586     // GLUT will extract all glut specific options so later on we only
587     // need wory about our own.
588     xglutInit(&argc, argv);
589
590     // Define Display Parameters
591     xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
592
593     // Define initial window size
594     xglutInitWindowSize(640, 480);
595
596     // Initialize windows
597     xglutCreateWindow("Flight Gear");
598
599     return(1);
600 }
601
602
603 // Initialize GLUT event handlers
604 int fgGlutInitEvents( void ) {
605     // call fgReshape() on window resizes
606     xglutReshapeFunc( fgReshape );
607
608     // call GLUTkey() on keyboard event
609     xglutKeyboardFunc( GLUTkey );
610     glutSpecialFunc( GLUTspecialkey );
611
612     // call fgMainLoop() whenever there is
613     // nothing else to do
614     xglutIdleFunc( fgMainLoop );
615
616     // draw the scene
617     xglutDisplayFunc( fgRenderFrame );
618
619     return(1);
620 }
621
622
623 // Main ...
624 int main( int argc, char **argv ) {
625     fgFLIGHT *f;
626     int result;  // Used in command line argument.
627
628     f = current_aircraft.flight;
629
630     // Initialize the debugging output system
631     fgInitDebug();
632
633     fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear:  Version %s\n\n", VERSION);
634
635     // Initialize the Window/Graphics environment.
636     if( !fgGlutInit(argc, argv) ) {
637         fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
638     }
639
640     // Parse remaining command line options
641     result = current_options.parse(argc, argv);
642
643     if ( result != FG_OPTIONS_OK ) {
644         // Something must have gone horribly wrong with the command
645         // line parsing or maybe the user just requested help ... :-)
646         current_options.usage();
647         fgPrintf( FG_GENERAL, FG_EXIT, "\nShutting down ...\n");
648     }
649
650     // These are a few miscellaneous things that aren't really
651     // "subsystems" but still need to be initialized.
652     if( !fgInitGeneral()) {
653         fgPrintf( FG_GENERAL, FG_EXIT, "General initializations failed ...\n" );
654     }
655
656     // This is the top level init routine which calls all the other
657     // subsystem initialization routines.  If you are adding a
658     // subsystem to flight gear, its initialization call should
659     // located in this routine.
660     if( !fgInitSubsystems()) {
661         fgPrintf( FG_GENERAL, FG_EXIT,
662                   "Subsystem initializations failed ...\n" );
663     }
664
665     // setup OpenGL view parameters
666     fgInitVisuals();
667
668     if ( use_signals ) {
669         // init timer routines, signals, etc.  Arrange for an alarm
670         // signal to be generated, etc.
671         fgInitTimeDepCalcs();
672     }
673
674     // Initialize the various GLUT Event Handlers.
675     if( !fgGlutInitEvents() ) {
676         fgPrintf( FG_GENERAL, FG_EXIT, 
677                   "GLUT event handler initialization failed ...\n" );
678     }
679
680     // pass control off to the master GLUT event handler
681     glutMainLoop();
682
683     // we never actually get here ... but just in case ... :-)
684     return(0);
685 }
686
687
688 #ifdef __SUNPRO_CC
689 extern "C" {
690     void __eprintf( void ) {
691     }
692 }
693 #endif
694
695
696 // $Log$
697 // Revision 1.4  1998/04/24 14:19:30  curt
698 // Fog tweaks.
699 //
700 // Revision 1.3  1998/04/24 00:49:18  curt
701 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
702 // Trying out some different option parsing code.
703 // Some code reorganization.
704 //
705 // Revision 1.2  1998/04/22 13:25:41  curt
706 // C++ - ifing the code.
707 // Starting a bit of reorganization of lighting code.
708 //
709 // Revision 1.1  1998/04/21 17:02:39  curt
710 // Prepairing for C++ integration.
711 //
712 // Revision 1.71  1998/04/18 04:11:26  curt
713 // Moved fg_debug to it's own library, added zlib support.
714 //
715 // Revision 1.70  1998/04/14 02:21:02  curt
716 // Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
717 // <jgoeke@voyager.net>
718 //
719 // Revision 1.69  1998/04/08 23:35:34  curt
720 // Tweaks to Gnu automake/autoconf system.
721 //
722 // Revision 1.68  1998/04/03 22:09:03  curt
723 // Converting to Gnu autoconf system.
724 //
725 // Revision 1.67  1998/03/23 21:24:37  curt
726 // Source code formating tweaks.
727 //
728 // Revision 1.66  1998/03/14 00:31:20  curt
729 // Beginning initial terrain texturing experiments.
730 //
731 // Revision 1.65  1998/03/09 22:45:57  curt
732 // Minor tweaks for building on sparc platform.
733 //
734 // Revision 1.64  1998/02/20 00:16:23  curt
735 // Thursday's tweaks.
736 //
737 // Revision 1.63  1998/02/16 16:17:39  curt
738 // Minor tweaks.
739 //
740 // Revision 1.62  1998/02/16 13:39:42  curt
741 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
742 // tiles to occasionally be missing.
743 //
744 // Revision 1.61  1998/02/12 21:59:46  curt
745 // Incorporated code changes contributed by Charlie Hotchkiss
746 // <chotchkiss@namg.us.anritsu.com>
747 //
748 // Revision 1.60  1998/02/11 02:50:40  curt
749 // Minor changes.
750 //
751 // Revision 1.59  1998/02/09 22:56:54  curt
752 // Removed "depend" files from cvs control.  Other minor make tweaks.
753 //
754 // Revision 1.58  1998/02/09 15:07:49  curt
755 // Minor tweaks.
756 //
757 // Revision 1.57  1998/02/07 15:29:40  curt
758 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
759 // <chotchkiss@namg.us.anritsu.com>
760 //
761 // Revision 1.56  1998/02/03 23:20:23  curt
762 // Lots of little tweaks to fix various consistency problems discovered by
763 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
764 // passed arguments along to the real printf().  Also incorporated HUD changes
765 // by Michele America.
766 //
767 // Revision 1.55  1998/02/02 20:53:58  curt
768 // Incorporated Durk's changes.
769 //
770 // Revision 1.54  1998/01/31 00:43:10  curt
771 // Added MetroWorks patches from Carmen Volpe.
772 //
773 // Revision 1.53  1998/01/27 18:35:54  curt
774 // Minor tweaks.
775 //
776 // Revision 1.52  1998/01/27 00:47:56  curt
777 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
778 // system and commandline/config file processing code.
779 //
780 // Revision 1.51  1998/01/26 15:57:05  curt
781 // Tweaks for dynamic scenery development.
782 //
783 // Revision 1.50  1998/01/19 19:27:07  curt
784 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
785 // This should simplify things tremendously.
786 //
787 // Revision 1.49  1998/01/19 18:40:31  curt
788 // Tons of little changes to clean up the code and to remove fatal errors
789 // when building with the c++ compiler.
790 //
791 // Revision 1.48  1998/01/19 18:35:46  curt
792 // Minor tweaks and fixes for cygwin32.
793 //
794 // Revision 1.47  1998/01/13 00:23:08  curt
795 // Initial changes to support loading and management of scenery tiles.  Note,
796 // there's still a fair amount of work left to be done.
797 //
798 // Revision 1.46  1998/01/08 02:22:06  curt
799 // Beginning to integrate Tile management subsystem.
800 //
801 // Revision 1.45  1998/01/07 03:18:55  curt
802 // Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
803 //
804 // Revision 1.44  1997/12/30 22:22:31  curt
805 // Further integration of event manager.
806 //
807 // Revision 1.43  1997/12/30 20:47:43  curt
808 // Integrated new event manager with subsystem initializations.
809 //
810 // Revision 1.42  1997/12/30 16:36:47  curt
811 // Merged in Durk's changes ...
812 //
813 // Revision 1.41  1997/12/30 13:06:56  curt
814 // A couple lighting tweaks ...
815 //
816 // Revision 1.40  1997/12/30 01:38:37  curt
817 // Switched back to per vertex normals and smooth shading for terrain.
818 //
819 // Revision 1.39  1997/12/22 23:45:45  curt
820 // First stab at sunset/sunrise sky glow effects.
821 //
822 // Revision 1.38  1997/12/22 04:14:28  curt
823 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
824 //
825 // Revision 1.37  1997/12/19 23:34:03  curt
826 // Lot's of tweaking with sky rendering and lighting.
827 //
828 // Revision 1.36  1997/12/19 16:44:57  curt
829 // Working on scene rendering order and options.
830 //
831 // Revision 1.35  1997/12/18 23:32:32  curt
832 // First stab at sky dome actually starting to look reasonable. :-)
833 //
834 // Revision 1.34  1997/12/17 23:13:34  curt
835 // Began working on rendering a sky.
836 //
837 // Revision 1.33  1997/12/15 23:54:45  curt
838 // Add xgl wrappers for debugging.
839 // Generate terrain normals on the fly.
840 //
841 // Revision 1.32  1997/12/15 20:59:08  curt
842 // Misc. tweaks.
843 //
844 // Revision 1.31  1997/12/12 21:41:25  curt
845 // More light/material property tweaking ... still a ways off.
846 //
847 // Revision 1.30  1997/12/12 19:52:47  curt
848 // Working on lightling and material properties.
849 //
850 // Revision 1.29  1997/12/11 04:43:54  curt
851 // Fixed sun vector and lighting problems.  I thing the moon is now lit
852 // correctly.
853 //
854 // Revision 1.28  1997/12/10 22:37:45  curt
855 // Prepended "fg" on the name of all global structures that didn't have it yet.
856 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
857 //
858 // Revision 1.27  1997/12/09 05:11:54  curt
859 // Working on tweaking lighting.
860 //
861 // Revision 1.26  1997/12/09 04:25:29  curt
862 // Working on adding a global lighting params structure.
863 //
864 // Revision 1.25  1997/12/08 22:54:09  curt
865 // Enabled GL_CULL_FACE.
866 //
867 // Revision 1.24  1997/11/25 19:25:32  curt
868 // Changes to integrate Durk's moon/sun code updates + clean up.
869 //
870 // Revision 1.23  1997/11/15 18:16:34  curt
871 // minor tweaks.
872 //
873 // Revision 1.22  1997/10/30 12:38:41  curt
874 // Working on new scenery subsystem.
875 //
876 // Revision 1.21  1997/09/23 00:29:38  curt
877 // Tweaks to get things to compile with gcc-win32.
878 //
879 // Revision 1.20  1997/09/22 14:44:19  curt
880 // Continuing to try to align stars correctly.
881 //
882 // Revision 1.19  1997/09/18 16:20:08  curt
883 // At dusk/dawn add/remove stars in stages.
884 //
885 // Revision 1.18  1997/09/16 22:14:51  curt
886 // Tweaked time of day lighting equations.  Don't draw stars during the day.
887 //
888 // Revision 1.17  1997/09/16 15:50:29  curt
889 // Working on star alignment and time issues.
890 //
891 // Revision 1.16  1997/09/13 02:00:06  curt
892 // Mostly working on stars and generating sidereal time for accurate star
893 // placement.
894 //
895 // Revision 1.15  1997/09/05 14:17:27  curt
896 // More tweaking with stars.
897 //
898 // Revision 1.14  1997/09/05 01:35:53  curt
899 // Working on getting stars right.
900 //
901 // Revision 1.13  1997/09/04 02:17:34  curt
902 // Shufflin' stuff.
903 //
904 // Revision 1.12  1997/08/27 21:32:24  curt
905 // Restructured view calculation code.  Added stars.
906 //
907 // Revision 1.11  1997/08/27 03:30:16  curt
908 // Changed naming scheme of basic shared structures.
909 //
910 // Revision 1.10  1997/08/25 20:27:22  curt
911 // Merged in initial HUD and Joystick code.
912 //
913 // Revision 1.9  1997/08/22 21:34:39  curt
914 // Doing a bit of reorganizing and house cleaning.
915 //
916 // Revision 1.8  1997/08/19 23:55:03  curt
917 // Worked on better simulating real lighting.
918 //
919 // Revision 1.7  1997/08/16 12:22:38  curt
920 // Working on improving the lighting/shading.
921 //
922 // Revision 1.6  1997/08/13 20:24:56  curt
923 // Changes due to changing sunpos interface.
924 //
925 // Revision 1.5  1997/08/06 21:08:32  curt
926 // Sun position now really* works (I think) ... I still have sun time warping
927 // code in place, probably should remove it soon.
928 //
929 // Revision 1.4  1997/08/06 15:41:26  curt
930 // Working on correct sun position.
931 //
932 // Revision 1.3  1997/08/06 00:24:22  curt
933 // Working on correct real time sun lighting.
934 //
935 // Revision 1.2  1997/08/04 20:25:15  curt
936 // Organizational tweaking.
937 //
938 // Revision 1.1  1997/08/02 18:45:00  curt
939 // Renamed GLmain.c GLUTmain.c
940 //
941 // Revision 1.43  1997/08/02 16:23:47  curt
942 // Misc. tweaks.
943 //
944 // Revision 1.42  1997/08/01 19:43:33  curt
945 // Making progress with coordinate system overhaul.
946 //
947 // Revision 1.41  1997/07/31 22:52:37  curt
948 // Working on redoing internal coordinate systems & scenery transformations.
949 //
950 // Revision 1.40  1997/07/30 16:12:42  curt
951 // Moved fg_random routines from Util/ to Math/
952 //
953 // Revision 1.39  1997/07/21 14:45:01  curt
954 // Minor tweaks.
955 //
956 // Revision 1.38  1997/07/19 23:04:47  curt
957 // Added an initial weather section.
958 //
959 // Revision 1.37  1997/07/19 22:34:02  curt
960 // Moved PI definitions to ../constants.h
961 // Moved random() stuff to ../Utils/ and renamed fg_random()
962 //
963 // Revision 1.36  1997/07/18 23:41:25  curt
964 // Tweaks for building with Cygnus Win32 compiler.
965 //
966 // Revision 1.35  1997/07/18 14:28:34  curt
967 // Hacked in some support for wind/turbulence.
968 //
969 // Revision 1.34  1997/07/16 20:04:48  curt
970 // Minor tweaks to aid Win32 port.
971 //
972 // Revision 1.33  1997/07/12 03:50:20  curt
973 // Added an #include <Windows32/Base.h> to help compiling for Win32
974 //
975 // Revision 1.32  1997/07/11 03:23:18  curt
976 // Solved some scenery display/orientation problems.  Still have a positioning
977 // (or transformation?) problem.
978 //
979 // Revision 1.31  1997/07/11 01:29:58  curt
980 // More tweaking of terrian floor.
981 //
982 // Revision 1.30  1997/07/10 04:26:37  curt
983 // We now can interpolated ground elevation for any position in the grid.  We
984 // can use this to enforce a "hard" ground.  We still need to enforce some
985 // bounds checking so that we don't try to lookup data points outside the
986 // grid data set.
987 //
988 // Revision 1.29  1997/07/09 21:31:12  curt
989 // Working on making the ground "hard."
990 //
991 // Revision 1.28  1997/07/08 18:20:12  curt
992 // Working on establishing a hard ground.
993 //
994 // Revision 1.27  1997/07/07 20:59:49  curt
995 // Working on scenery transformations to enable us to fly fluidly over the
996 // poles with no discontinuity/distortion in scenery.
997 //
998 // Revision 1.26  1997/07/05 20:43:34  curt
999 // renamed mat3 directory to Math so we could add other math related routines.
1000 //
1001 // Revision 1.25  1997/06/29 21:19:17  curt
1002 // Working on scenery management system.
1003 //
1004 // Revision 1.24  1997/06/26 22:14:53  curt
1005 // Beginning work on a scenery management system.
1006 //
1007 // Revision 1.23  1997/06/26 19:08:33  curt
1008 // Restructuring make, adding automatic "make dep" support.
1009 //
1010 // Revision 1.22  1997/06/25 15:39:47  curt
1011 // Minor changes to compile with rsxnt/win32.
1012 //
1013 // Revision 1.21  1997/06/22 21:44:41  curt
1014 // Working on intergrating the VRML (subset) parser.
1015 //
1016 // Revision 1.20  1997/06/21 17:12:53  curt
1017 // Capitalized subdirectory names.
1018 //
1019 // Revision 1.19  1997/06/18 04:10:31  curt
1020 // A couple more runway tweaks ...
1021 //
1022 // Revision 1.18  1997/06/18 02:21:24  curt
1023 // Hacked in a runway
1024 //
1025 // Revision 1.17  1997/06/17 16:51:58  curt
1026 // Timer interval stuff now uses gettimeofday() instead of ftime()
1027 //
1028 // Revision 1.16  1997/06/17 04:19:16  curt
1029 // More timer related tweaks with respect to view direction changes.
1030 //
1031 // Revision 1.15  1997/06/17 03:41:10  curt
1032 // Nonsignal based interval timing is now working.
1033 // This would be a good time to look at cleaning up the code structure a bit.
1034 //
1035 // Revision 1.14  1997/06/16 19:32:51  curt
1036 // Starting to add general timer support.
1037 //
1038 // Revision 1.13  1997/06/02 03:40:06  curt
1039 // A tiny bit more view tweaking.
1040 //
1041 // Revision 1.12  1997/06/02 03:01:38  curt
1042 // Working on views (side, front, back, transitions, etc.)
1043 //
1044 // Revision 1.11  1997/05/31 19:16:25  curt
1045 // Elevator trim added.
1046 //
1047 // Revision 1.10  1997/05/31 04:13:52  curt
1048 // WE CAN NOW FLY!!!
1049 //
1050 // Continuing work on the LaRCsim flight model integration.
1051 // Added some MSFS-like keyboard input handling.
1052 //
1053 // Revision 1.9  1997/05/30 19:27:01  curt
1054 // The LaRCsim flight model is starting to look like it is working.
1055 //
1056 // Revision 1.8  1997/05/30 03:54:10  curt
1057 // Made a bit more progress towards integrating the LaRCsim flight model.
1058 //
1059 // Revision 1.7  1997/05/29 22:39:49  curt
1060 // Working on incorporating the LaRCsim flight model.
1061 //
1062 // Revision 1.6  1997/05/29 12:31:39  curt
1063 // Minor tweaks, moving towards general flight model integration.
1064 //
1065 // Revision 1.5  1997/05/29 02:33:23  curt
1066 // Updated to reflect changing interfaces in other "modules."
1067 //
1068 // Revision 1.4  1997/05/27 17:44:31  curt
1069 // Renamed & rearranged variables and routines.   Added some initial simple
1070 // timer/alarm routines so the flight model can be updated on a regular 
1071 // interval.
1072 //
1073 // Revision 1.3  1997/05/23 15:40:25  curt
1074 // Added GNU copyright headers.
1075 // Fog now works!
1076 //
1077 // Revision 1.2  1997/05/23 00:35:12  curt
1078 // Trying to get fog to work ...
1079 //
1080 // Revision 1.1  1997/05/21 15:57:51  curt
1081 // Renamed due to added GLUT support.
1082 //
1083 // Revision 1.3  1997/05/19 18:22:42  curt
1084 // Parameter tweaking ... starting to stub in fog support.
1085 //
1086 // Revision 1.2  1997/05/17 00:17:34  curt
1087 // Trying to stub in support for standard OpenGL.
1088 //
1089 // Revision 1.1  1997/05/16 16:05:52  curt
1090 // Initial revision.
1091 //